【发布时间】:2014-04-17 13:49:24
【问题描述】:
我正在尝试让我的客户端订阅发生在我的服务器上的事件。
我的界面如下所示:
public delegate void RemoteEventHandler(object sender, ClientEventArgs args);
[Serializable]
public class ClientEventArgs : EventArgs
{
public ClientEventArgs()
{ }
public ClientEventArgs(Client _client)
{
MyClient = _client;
}
public Client MyClient { get; set; }
}
public interface IMonitor
{
event RemoteEventHandler RemoteEvent;
}
我的服务器类如下所示:
public class ConnectionManager : MarshalByRefObject, IMonitor
{
public event RemoteEventHandler RemoteEvent;
// call the below code when th event should fire.
if (RemoteEvent != null)
RemoteEvent(this, new ClientEventArgs(e.MyClient));
}
然后要在服务器上设置我的频道,我这样做:
BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 5001;
TcpChannel channel = new TcpChannel(props, null, provider);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(ConnectionManager),
ConnectionManager",
WellKnownObjectMode.Singleton);
并在客户端设置频道并订阅事件:
TcpChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel, false);
_monitorObject = (IMonitor)Activator.GetObject(
typeof(IMonitor),
"tcp://localhost:5001/ConnectionManager");
_monitorObject.RemoteEvent += _monitorObject_RemoteEvent;
谁能解释一下这是哪里出了问题?
例外:
System.MissingMethodException 未处理 HResult=-2146233069 消息=没有为此对象定义无参数构造函数。
来源=mscorlib
【问题讨论】:
-
异常是否有内部异常?
-
加载主程序集或其依赖项之一失败?
-
那么您可能缺少引用的程序集。你只复制exe吗?
-
修复引用后,我得到一个无参数少构造函数错误?
-
你提供了一个很好的堆栈跟踪,但不是实际的异常......
标签: c# events interface .net-remoting