2011-04-02 172 views
3

我想做一个简单的程序,发送一个id作为一个int,并根据id获取数据。但我不断收到这个错误。无法加载类型错误,.Net Remoting

Cannot load type 'remote.RemoteObjectClass, remoteclient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. 

服务器

 TcpServerChannel channel = new TcpServerChannel(8086); 
     ChannelServices.RegisterChannel(channel); 

     RemotingConfiguration.RegisterWellKnownServiceType(typeof(Class1), "1", 
     WellKnownObjectMode.Singleton); 
     label1.Text = "started"; 

客户

RemoteObjectClass obj1 = (RemoteObjectClass)Activator.GetObject(
     typeof(RemoteObjectClass), 
     "tcp://localhost:8086/1"); 

     if (obj1 == null) 
     { 

      label1.Text = "Could not locate TCP server"; 

     } 
     Class1 cl = obj1.kk(Convert.ToInt32(textBox1.Text)); -- **got error here** 

RemoteObjectClass

class RemoteObjectClass : System.MarshalByRefObject 
{ 

    public int c(int i) 
    { 
     return 33; 
    } 
    public Class1 kk(int i) 
    { 
     Class1 k = new Class1(); 
     return k; 
    } 

ClassLibrary

namespace ClassLibrary1 
{ 
    public class Class1 : System.MarshalByRefObject 

    { 
     public string ad; 

     public int id; 
    } 
} 
+0

尝试构建应用程序。如果您已经构建它,请清理并*重建*。 – 2011-04-02 13:40:45

+0

问题使用@benjamin answer在Mono下解决,错误如下:System.Runtime.Remoting.RemotingException:无法从客户端类型'remote.RemoteObjectClass,remoteclient,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'转换为服务器类型'remote.RemoteObjectClass' – 2012-09-14 14:32:14

回答

4

如果主叫和被叫的RemoteObject类是在不同的命名空间可能会出现此错误。

+0

非常感谢您收到此提示。我真的很疑惑,为什么我有这种遗憾!远程处理中使用的接口和/或对象必须在相同的名称空间内! – 2012-09-14 14:26:14

相关问题