我想讓我的客戶端訂閱發生在我的服務器上的事件。參數少構造函數錯誤
我有一個看起來像這樣的接口:
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消息=此對象定義無參數的構造函數。使用
Serializable
當你需要無參數的構造函數:
來源= mscorlib程序
異常是否有內部異常? –
它無法加載主程序集或它的一個依賴項? – dev6754
然後你可能會缺少一個引用程序集。你只複製了exe文件嗎? –