我有一个包含事件的远程处理类。但是当我尝试在客户端设置这些事件的处理程序时,我收到异常。我的代码如下所示:
//In common library
class RemoteClass : MarshalByRefObject
{
public event EventHandler SomeEvent = null;
public void SomeMethod () {}
}
//On client-side
RemoteClass r = (RemoteClass) RemotingServer.Connect (typeof(RemoteClass), "myURL");
r.SomeMethod (); //Everything is OK here.
r.SomeEvent += delegate (object o, EventArgs e) { }; //Exception:Type
System.DelegateSerializationHolder
及其派生类型(例如 System.DelegateSerializationHolder
)不允许在此安全级别进行反序列化。
我做错了什么?
最佳答案
In the .NET Framework, the default security level for distributed communication (remoting) is low. This affects passing the user-defined object type to remote methods. You might need to adjust the default security level to full in some cases to allow serialization of objects.
如果您使用 ASP.Net,请按以下步骤设置安全(信任)级别:
关于c# - 如何在 .NET Remoting 中远程处理事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7608826/