1

AppDomainを作成し、Event 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 not marked as serializable.」というエラーが表示されます。

編集: だから私は MainWindowViewModel クラスに Serializable を配置しましたが、それでもうまくいきました。アプリケーションを実行すると、同じエラーが発生します. 助けてください。ありがとうございました

[SecurityPermission(SecurityAction.Demand, 
                    Flags = SecurityPermissionFlag.AllFlags)] 
public class MainWindowViewModel : ViewModelBase
{......}

編集

public MainWindowViewModel()
{
    AppDomain current = AppDomain.CurrentDomain;
    current.UnhandledException += 
        new UnhandledExceptionEventHandler(current_UnhandledException);
}

ここでの私の質問は、appdomain の子が 2 つある場合、この例外がどの子からのものかをどのように知ることができますか?

4

1 に答える 1

3

これは間違いなくこれを行う方法ではありません。

エラーが発生する理由は、型が appdomain の境界を越えようとしていて、シリアライズ可能またはリモート可能なオブジェクトではないため、失敗しているためです。これは、起こりたくないことでもあります。

解決策として、サンドボックス アプリケーション ドメイン内でそのイベントをサブスクライブする必要があります。

そのハンドラー内で、選択したリモート インターフェイス/サービスを介して、例外情報を「メイン」アプリ ドメインに転送できます。

于 2012-07-24T06:46:10.550 に答える