gpt4 book ai didi

c# - 如何在 .NET Remoting 中远程处理事件?

转载 作者:行者123 更新时间:2023-12-02 13:42:46 24 4
gpt4 key购买 nike

我有一个包含事件的远程处理类。但是当我尝试在客户端设置这些事件的处理程序时,我收到异常。我的代码如下所示:

    //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)不允许在此安全级别进行反序列化。

我做错了什么?

最佳答案

https://web.archive.org/web/20141009214120/http://msdn.microsoft.com/en-us/library/61w7kz4b(v=vs.80).aspx

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,请按以下步骤设置安全(信任)级别:

http://msdn.microsoft.com/en-us/library/ff648344.aspx

关于c# - 如何在 .NET Remoting 中远程处理事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7608826/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com