【发布时间】:2012-07-22 10:45:17
【问题描述】:
我创建了一个 AppDomain 并订阅了事件 UnhandledException
AppDomain sandbox1 = AppDomain.CreateDomain("SandBox1");
sandbox1.UnhandledException +=
new UnhandledExceptionEventHandler(sandbox1_UnhandledException);
当我的代码单步执行 UnhandledException 订阅时,它提示错误 "Type 'MainUI.MainWindowViewModel' in assembly 'MainUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is notmarked as serializable. "
编辑: 所以我将 Serializable 放在我的 MainWindowViewModel 类上,但它仍然通过了。当我运行应用程序时,出现相同的错误 “在程序集 'MainUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 中键入 'MainUI.MainWindowViewModel' 未标记为可序列化。”。请帮忙。谢谢
[SecurityPermission(SecurityAction.Demand,
Flags = SecurityPermissionFlag.AllFlags)]
public class MainWindowViewModel : ViewModelBase
{......}
编辑
public MainWindowViewModel()
{
AppDomain current = AppDomain.CurrentDomain;
current.UnhandledException +=
new UnhandledExceptionEventHandler(current_UnhandledException);
}
我的问题是,如果我有 2 个 appdomain 孩子,我怎么知道这个异常来自哪个孩子?
【问题讨论】:
-
“但它仍然没有工作” - 你得到 same 异常了吗? 不同的例外?还是屏幕变成绿色并带有粉红色斑点?请定义“不起作用”。是否只是要求基类为
[Serializable]?还是...? -
@xscape:我为您提供了答案。如果您不遵循它,您可能需要尝试应用程序域并进行更多的远程处理。一开始很难,但知道这是一件非常有价值的事情。
标签: c# appdomain serializable unhandled-exception