what happens when an object derives from MarshalByRefObject and is also marked [Serializable]?

安稳与你 提交于 2019-12-07 12:55:36

问题


I'm working on my first project that uses AppDomains and I'm wondering what happens when an object derives from MarshalByRefObject and is also marked [Serializable]?

for example:

[Serializable]
public class DummyClass: MarshalByRefObject
{

}

回答1:


It gets marshalled by reference, but can still be serialised for other use-cases for serialisation. There's an implementation detail to this that is interesting enough to be worth noting: The formatter that is serialising for remoting uses a SurrogateSelector that will produce a proxy for any MarshalByRefObject it serialises, hence serialising will still result in marshalling by reference. Other serialisation uses won't have that SurrogateSelector and so won't have that effect.



来源:https://stackoverflow.com/questions/8799202/what-happens-when-an-object-derives-from-marshalbyrefobject-and-is-also-marked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!