从应用程序域中解包不可序列化的类
因为并非我想要实例化的类中使用的所有类都是可序列化的,所以我无法解包。
这可能吗?
var appdom = AppDomain.CreateDomain(amServiceable.GetType().ToString());
var objectHandle = appdom.CreateInstance(amServiceable.GetType().Assembly.FullName,
amServiceable.GetType().FullName);
var plugin = objectHandle.Unwrap() as IPlugin //throws an error. that some class in not marked serializable.
Because not all the classes used in the class I want to instantiate are serializable I can't unwrap.
Is this possible?
var appdom = AppDomain.CreateDomain(amServiceable.GetType().ToString());
var objectHandle = appdom.CreateInstance(amServiceable.GetType().Assembly.FullName,
amServiceable.GetType().FullName);
var plugin = objectHandle.Unwrap() as IPlugin //throws an error. that some class in not marked serializable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了在对象上使用
Unwrap
方法,它必须从MarshalByRefObject
派生。如果您要操作的对象没有,那么唯一的其他选择是使用不同的MarshalByRefObject
来操作其他域中的对象In order to use the
Unwrap
method on an object it must derive fromMarshalByRefObject
. If the object you want to manipulate doesn't then the only other choice is to use a differentMarshalByRefObject
to manipulate the object in the other domain