我试图找出是否有一种方法可以创建从应用程序域引用的我的对象的本地实例,原因是在该方法的所有执行过程中我得到了大量的喋喋不休。因此,不必一直调用远程对象,我只想调用在方法内创建的本地实例。
我一直在研究 RemotingServices Marshal 和 GetObjectData 方法,但无法弄清楚它们是否有效,谷歌也没有帮助
所以类定义如下
[XmlRoot("SI")]
public class SI : MarshalByRefObject, IXmlSerializable
然后运行时类的一个实例看起来像这样。
Name: Service
Value: {System.Runtime.Remoting.Proxies.__TransparentProxy}
Type: SI {System.Runtime.Remoting.Proxies.__TransparentProxy}
我希望按照以下方式完成我所需要的
var uri =RemotingServices.GetObjectUri(Service);
var serv = RemotingServices.Marshal(Service, uri, typeof(SI)); //Service is the object I described above
SerializationInfo info = new SerializationInfo(typeof(SI), new FormatterConverter());
StreamingContext context = new StreamingContext(StreamingContextStates.All);
serv.GetObjectData(info, context);
var t2 = serv.GetRealObject(context);
调用 GetRealObject 时出现以下错误 “尝试读取或写入受保护的内存。这通常表明其他内存已损坏。”
我仍然没有找到任何方法来实现这一点,有人可能有一些建议吗?