我创建一个AppDomain和预订事件UnhandledExceptionC#:AppDomain中UnhandledException错误
AppDomain sandbox1 = AppDomain.CreateDomain("SandBox1");
sandbox1.UnhandledException +=
new UnhandledExceptionEventHandler(sandbox1_UnhandledException);
当通过UnhandledException订阅我的代码的步骤,它在装配提示出错“类型“MainUI.MainWindowViewModel“MainUI ,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'未标记为可序列化。“
编辑: 所以我把序列化我MainWindowViewModel类,但仍然它没有经历过。当我运行应用程序相同的错误去“类型'MainUI.MainWindowViewModel'在程序集'MainUI,版本= 1.0.0.0,文化=中性,PublicKeyToken = null'未被标记为可序列化。。请帮忙。谢谢
[SecurityPermission(SecurityAction.Demand,
Flags = SecurityPermissionFlag.AllFlags)]
public class MainWindowViewModel : ViewModelBase
{......}
编辑
public MainWindowViewModel()
{
AppDomain current = AppDomain.CurrentDomain;
current.UnhandledException +=
new UnhandledExceptionEventHandler(current_UnhandledException);
}
我的问题在这里,如果我有2个孩子的AppDomain,我怎么知道,这个例外是来自哪个孩子?
“但它仍然没有工作” - 你有*相同*例外吗?一个*不同*异常?或者屏幕变成粉红色斑点的绿色?请定义“没有工作”。它只是要求基类是'[Serializable]'?要么...? – 2012-07-24 06:42:26
请看我的编辑 – xscape 2012-07-24 06:48:18
@xscape:我提供了你的答案。如果你不遵循它,你可能需要尝试一下appdomains和remoting。起初相当困难,但知道的非常有价值。 – leppie 2012-07-24 07:04:03