我用.net 的remoting 开发一个客户端和服务器端,当我调试服务器端的时候出现如下错误:
错误 1 程序“C:\Documents and Settings\liu\My Documents\Visual Studio 2008\Projects\YABS\YABS.Shared\obj\Debug\YABS.Shared.exe”不包含适合于入口点的静态“Main”方法.
请问是什么原因?
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
//using YABS.Shared;namespace YABS.Server
{
     public class Server
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("***Welcome***");            SoapServerFormatterSinkProvider serverProvider = 
                new SoapServerFormatterSinkProvider();
            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;            SoapClientFormatterSinkProvider clientProvider = 
                new SoapClientFormatterSinkProvider();
            IDictionary properties = new Hashtable();
            properties.Add("port", 6123);
            HttpChannel chan = new HttpChannel(properties,clientProvider, serverProvider); 
            ChannelServices.RegisterChannel(chan,false);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject),"yabs",WellKnownObjectMode.Singleton);            Console.WriteLine("Server is started.");
        
        
        }    }
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting.Lifetime;namespace YABS.Server
{
    public class RemoteObject : MarshalByRefObject,IRemoteObject
    {
        public void RemotObject()
        {
            Console.WriteLine("remote object is instanced");
        }        private class Article
        {
            public  uint id = 0;
            public  string name = "";
            public  uint price= 0;
            public  string vendor = "";
            public  string description;
            public  string bider="";
            
            public Article(uint id, string name, uint price, string vendor, string description,string bider)
            {
                this.id = id;
                this.name = name;
                this.price = price;
                this.vendor = vendor;
                this.description = description;
                this.bider = bider;            }            public void setPrice(uint price)
            {
                this.price = price;
            }
            public uint getPrice()
            {
                return this.price;
            }
        }
            
            List<Article> articles = new List<Article>();            public string regArticle(uint id, string name, uint price, string vendor, string description, string bider)
            {
                try
                {
                    Console.WriteLine("Usage: id| name|price|vendor|description");
                    string str1 = Console.ReadLine();
                    string[] strArray = str1.Trim().Split('|');
                    id = uint.Parse(strArray[0]);
                    name = strArray[1];
                    price = uint.Parse(strArray[2]);
                    vendor = strArray[3];
                    description = strArray[4];                    Article myArticle = new Article(id,name,price,vendor,description,bider);
                    articles.Add(myArticle);
                    return "OK";
                }
                catch
                {
                    Console.WriteLine("Error: Offering an article FAILED");
                    return "FAILED";
                }            }            public override object InitializeLifetimeService()
            {
                ILease lease = (ILease)base.InitializeLifetimeService();
                if (lease.CurrentState== LeaseState.Initial)
                {
                   lease.InitialLeaseTime= TimeSpan.FromMinutes(100);
                   lease.RenewOnCallTime= TimeSpan.FromMinutes(20);
                 }
                return lease; //return null = Objektlebtso langewieProzess
             }
            
     
            //list current Bid and left duration
            public string list()
            {
                string returnString = "";
                try
                {
                    foreach (Article myArticle in articles)
                    {
                        returnString += myArticle.id+"|"+myArticle.name + "|" + myArticle.price + "|" + myArticle.description + "|"+myArticle.description+"\r\n";
                        return returnString;
                    }
                    Console.WriteLine("FAILED");
                    return "FAILED";
                }
                catch
                {
                    Console.WriteLine("Error: List all articles FAILED");
                    return "FAILED";
                }
            }            public string getArticle(string name)
            {
                foreach (Article myArticle in articles)
                {
                    if (name.Trim().Equals(myArticle.name.Trim().ToLower()))
                    {
                        return "ok";
                    }
                }
                Console.WriteLine("FAILED");
                return "FAILED";
            }           public void Bid(uint id, uint price)
           {
                foreach(Article myArticle in articles)
                {
                    
                    if(id == myArticle.id)
                    {
                         if(price > myArticle.price )
                         {
                             myArticle.price = price;
                             Console.WriteLine("Biding Sucessful!");
                             break;
                         }
                         else
                         {
                             Console.WriteLine("Youre given price is too low!");
                             break;
                         }
                    }
                    else
                    {
                        Console.WriteLine("There is no associated article, please select again");
                        return;
                    }                }        
           }
           
          public string  winnNotify(int id)
          {
              foreach(Article myArticle in articles)
              {
                  if (id == myArticle.id)
                  {
                      return "Vendor: " + myArticle.vendor + ",  Winner" + myArticle.bider + ", Price" + myArticle.price;
                     
                  }
                 
              }
              Console.WriteLine("FAILED");
              return "FAILED";          }
                    
    }
}

解决方案 »

  1.   

    但是我的  class server 是引用class RemoteObject 呀,class server 有Main 函数呀
      

  2.   

    在解决方案管理器
    右键选择项目、属性、应用程序、启动对象下拉框
    看看里面有东西没?如果是多个选一个
    如果一个没有哪么可能你的代码中有,非标准字符;YABS.Shared.exe 就是你给的代码吗???
      

  3.   

    main 函数前加上[STA Thread]试试
      

  4.   

    这个问题多半设置为 dll 编译时才会出的啊?