AppDomainUnloadedExceptionとは? わかりやすく解説

AppDomainUnloadedException クラス

アンロードされたアプリケーション ドメインアクセスようとするスローされる例外

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class AppDomainUnloadedException
    Inherits SystemException
Dim instance As AppDomainUnloadedException
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class AppDomainUnloadedException : SystemException
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class AppDomainUnloadedException
 : public SystemException
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class AppDomainUnloadedException extends
 SystemException
SerializableAttribute 
ComVisibleAttribute(true) 
public class AppDomainUnloadedException extends
 SystemException
解説解説
使用例使用例

このセクションには、2 つコード例含まれています。1 つ目の例では、AppDomainUnloadedExceptionさまざまなスレッドに及ぼす影響示し2 つ目の例では、単一アプリケーション ドメインアンロード示します

例 1

アプリケーション ドメイン境界越えてマーシャリングできる TestClass クラス、および static (Visual Basic では Shared) ThreadProc メソッドを含む Example クラス定義するコード例次に示しますThreadProc メソッドは、アプリケーション ドメイン作成し、そのドメインTestClass オブジェクト作成してTestClassメソッド呼び出します。このメソッドは、実行中のドメインアンロードするため、AppDomainUnloadedException原因となります

未処理例外によって、タスクまたはスレッド終了しても、アプリケーション終了しないことを示すために、TestClass メソッドThreadPool スレッド通常のスレッドから例外処理行わず実行します次に例外処理されていない場合でも、このメソッドアプリケーション終了することを示すために、メソッドメイン アプリケーション スレッドから例外処理有無問わず実行します

Imports System
Imports System.Threading
Imports System.Runtime.InteropServices

Public Class Example
    
    Public Shared Sub Main()
 

        ' 1. Queue ThreadProc as a task for a ThreadPool thread.
        ThreadPool.QueueUserWorkItem(AddressOf ThreadProc, _
            " from a ThreadPool thread")
        Thread.Sleep(1000)
        
        ' 2. Execute ThreadProc on an ordinary thread.
        Dim t As New Thread(AddressOf
 ThreadProc)
        t.Start(" from an ordinary thread")
        t.Join()
        
        ' 3. Execute ThreadProc on the main thread, with 
        '    exception handling.
        Try
            ThreadProc(" from the main application thread (handled)")
        Catch adue As AppDomainUnloadedException
            Console.WriteLine("Main thread caught AppDomainUnloadedException:
 {0}", _
                adue.Message)
        End Try
        
        ' 4. Execute ThreadProc on the main thread without
        '    exception handling.
        ThreadProc(" from the main application thread (unhandled)")
        
        Console.WriteLine("Main: This message is never displayed.")
    
    End Sub 
    
    Private Shared Sub ThreadProc(ByVal
 state As Object) 
        ' Create an application domain, and create an instance
        ' of TestClass in the application domain. The first
        ' parameter of CreateInstanceAndUnwrap is the name of
        ' this executable. If you compile the example code using
        ' any name other than "Sample.exe", you must change
 the
        ' parameter appropriately.
        Dim ad As AppDomain = AppDomain.CreateDomain("TestDomain")
        Dim o As Object
 = ad.CreateInstanceAndUnwrap("Sample", "TestClass")
        Dim tc As TestClass = CType(o, TestClass)
        
        ' In the new application domain, execute a method that
        ' unloads the AppDomain. The unhandled exception this
        ' causes ends the current thread.
        tc.UnloadCurrentDomain(state)
        
        Console.WriteLine("ThreadProc: This message is never displayed.")
    
    End Sub
End Class 

' TestClass derives from MarshalByRefObject, so it can be marshaled
' across application domain boundaries. 
'
Public Class TestClass
    Inherits MarshalByRefObject
    
    Public Sub UnloadCurrentDomain(ByVal
 state As Object) 
        Console.WriteLine(vbLf & "Unloading the current AppDomain{0}.",
 state)
        
        ' Unload the current application domain. This causes
        ' an AppDomainUnloadedException to be thrown.
        '
        AppDomain.Unload(AppDomain.CurrentDomain)
    
    End Sub 
End Class 

' This code example produces output similar to the following:
'
'Unloading the current AppDomain from a ThreadPool thread.
'
'Unloading the current AppDomain from an ordinary thread.
'
'Unloading the current AppDomain from the main application thread (handled).
'Main thread caught AppDomainUnloadedException: The application domain
 in which the thread was running has been unloaded.
'
'Unloading the current AppDomain from the main application thread (unhandled).
'
'Unhandled Exception: System.AppDomainUnloadedException: The application
 domain in which the thread was running has been unloaded.
'   at TestClass.UnloadCurrentDomain(Object state)
'   at Example.ThreadProc(Object state)
'   at Example.Main()
' 
using System;
using System.Threading;
using System.Runtime.InteropServices;

public class Example
{
    public static void Main()
    {
        // 1. Queue ThreadProc as a task for a ThreadPool thread.
        ThreadPool.QueueUserWorkItem(ThreadProc, " from a ThreadPool thread");
        Thread.Sleep(1000);

        // 2. Execute ThreadProc on an ordinary thread.
        Thread t = new Thread(ThreadProc);
        t.Start(" from an ordinary thread");
        t.Join();

        // 3. Execute ThreadProc on the main thread, with 
        //    exception handling.
        try
        {
            ThreadProc(" from the main application thread (handled)");
        }
        catch (AppDomainUnloadedException adue)
        {
            Console.WriteLine("Main thread caught AppDomainUnloadedException:
 {0}", adue.Message);
        }

        // 4. Execute ThreadProc on the main thread without
        //    exception handling.
        ThreadProc(" from the main application thread (unhandled)");

        Console.WriteLine("Main: This message is never displayed.");
    }

    private static void
 ThreadProc(object state)
    {
        // Create an application domain, and create an instance
        // of TestClass in the application domain. The first
        // parameter of CreateInstanceAndUnwrap is the name of
        // this executable. If you compile the example code using
        // any name other than "Sample.exe", you must change
 the
        // parameter appropriately.
        AppDomain ad = AppDomain.CreateDomain("TestDomain");
        TestClass tc = (TestClass)ad.CreateInstanceAndUnwrap("Sample",
 "TestClass");

        // In the new application domain, execute a method that
        // unloads the AppDomain. The unhandled exception this
        // causes ends the current thread.
        tc.UnloadCurrentDomain(state);

        Console.WriteLine("ThreadProc: This message is never displayed.");
    }
}

// TestClass derives from MarshalByRefObject, so it can be marshaled
// across application domain boundaries. 
//
public class TestClass : MarshalByRefObject
{
    public void UnloadCurrentDomain(object
 state)
    {
        Console.WriteLine("\nUnloading the current AppDomain{0}.", state);
 
        // Unload the current application domain. This causes
        // an AppDomainUnloadedException to be thrown.
        //
        AppDomain.Unload(AppDomain.CurrentDomain);
    }
}

/* This code example produces output similar to the following:
Unloading the current AppDomain from a ThreadPool thread.

Unloading the current AppDomain from an ordinary thread.

Unloading the current AppDomain from the main application thread (handled).
Main thread caught AppDomainUnloadedException: The application domain in
 which the thread was running has been unloaded.

Unloading the current AppDomain from the main application thread (unhandled).

Unhandled Exception: System.AppDomainUnloadedException: The application domain in
 which the thread was running has been unloaded.
   at TestClass.UnloadCurrentDomain(Object state)
   at Example.ThreadProc(Object state)
   at Example.Main()
 */

例 2

アプリケーション ドメイン作成しアンロードするコード例次に示しますまた、この例では、アンロードされたドメインへのアクセス試行で、AppDomainUnloadedExceptionスローされることも示します

Imports System
Imports System.Reflection
Imports System.Security.Policy 'for evidence object

Class ADUnload
   
   Public Shared Sub Main()

      'Create evidence for the new appdomain.
      Dim adevidence As Evidence = AppDomain.CurrentDomain.Evidence

      ' Create the new application domain.
      Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain",
 adevidence)
      
      Console.WriteLine(("Host domain: " + AppDomain.CurrentDomain.FriendlyName))
      Console.WriteLine(("child domain: " + domain.FriendlyName))
      ' Unload the application domain.
      AppDomain.Unload(domain)
      
      Try
         Console.WriteLine()
         ' Note that the following statement creates an exception because
 the domain no longer exists.
         Console.WriteLine(("child domain: " + domain.FriendlyName))
      
      Catch e As AppDomainUnloadedException
         Console.WriteLine("The appdomain MyDomain does not exist.")
      End Try
   End Sub 'Main 
End Class 'ADUnload
using System;
using System.Reflection;
using System.Security.Policy;  //for evidence object
class ADUnload
{
    public static void Main()
    {

        //Create evidence for the new appdomain.
        Evidence adevidence = AppDomain.CurrentDomain.Evidence;

         // Create the new application domain.
         AppDomain domain = AppDomain.CreateDomain("MyDomain", adevidence);

                Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
                Console.WriteLine("child domain: " + domain.FriendlyName);
        // Unload the application domain.
        AppDomain.Unload(domain);

        try
        {
        Console.WriteLine();
        // Note that the following statement creates an exception because
 the domain no longer exists.
                Console.WriteLine("child domain: " + domain.FriendlyName);
        }

        catch (AppDomainUnloadedException e)
        {
        Console.WriteLine("The appdomain MyDomain does not exist.");
        }
        
    }
    
}
using namespace System;
using namespace System::Reflection;
using namespace System::Security::Policy;

//for evidence Object*
int main()
{
   
   //Create evidence for the new appdomain.
   Evidence^ adevidence = AppDomain::CurrentDomain->Evidence;
   
   // Create the new application domain.
   AppDomain^ domain = AppDomain::CreateDomain( "MyDomain", adevidence
 );
   Console::WriteLine( "Host domain: {0}", AppDomain::CurrentDomain->FriendlyName
 );
   Console::WriteLine( "child domain: {0}", domain->FriendlyName );
   
   // Unload the application domain.
   AppDomain::Unload( domain );
   try
   {
      Console::WriteLine();
      
      // Note that the following statement creates an exception because
 the domain no longer exists.
      Console::WriteLine( "child domain: {0}", domain->FriendlyName
 );
   }
   catch ( AppDomainUnloadedException^ /*e*/ ) 
   {
      Console::WriteLine( "The appdomain MyDomain does not exist." );
   }

}

import System.*;
import System.Reflection.*;
import System.Security.Policy.*; //for evidence object

class ADUnload
{
    public static void main(String[]
 args)
    {
        // Create evidence for the new appdomain.
        Evidence adEvidence = AppDomain.get_CurrentDomain().get_Evidence();

        // Create the new application domain.
        AppDomain domain = AppDomain.CreateDomain("MyDomain", adEvidence);

        Console.WriteLine("Host domain: " 
            + AppDomain.get_CurrentDomain().get_FriendlyName());
        Console.WriteLine("child domain: " + domain.get_FriendlyName());

        // Unload the application domain.
        AppDomain.Unload(domain);
        try {
            Console.WriteLine();

            // Note that the following statement creates an exception
 
            // because the domain no longer exists.
            Console.WriteLine("child domain: " + domain.get_FriendlyName());
        }
        catch (AppDomainUnloadedException e) {
            Console.WriteLine("The appdomain MyDomain does not exist.");
        }
    } //main
} //ADUnload
継承階層継承階層
System.Object
   System.Exception
     System.SystemException
      System.AppDomainUnloadedException
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

AppDomainUnloadedException コンストラクタ ()

AppDomainUnloadedException クラス新しインスタンス初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Dim instance As New AppDomainUnloadedException
public AppDomainUnloadedException ()
public:
AppDomainUnloadedException ()
public AppDomainUnloadedException ()
public function AppDomainUnloadedException
 ()
解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
AppDomainUnloadedException クラス
AppDomainUnloadedException メンバ
System 名前空間

AppDomainUnloadedException コンストラクタ (String, Exception)

指定したエラー メッセージと、この例外原因である内部例外への参照使用して、AppDomainUnloadedException クラス新しインスタンス初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    message As String, _
    innerException As Exception _
)
Dim message As String
Dim innerException As Exception

Dim instance As New AppDomainUnloadedException(message,
 innerException)
public AppDomainUnloadedException (
    string message,
    Exception innerException
)
public:
AppDomainUnloadedException (
    String^ message, 
    Exception^ innerException
)
public AppDomainUnloadedException (
    String message, 
    Exception innerException
)
public function AppDomainUnloadedException
 (
    message : String, 
    innerException : Exception
)

パラメータ

message

エラー説明するメッセージ

innerException

現在の例外の原因である例外innerException パラメータnull 参照ない場合は、内部例外処理する catch ブロック現在の例外が発生します

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
AppDomainUnloadedException クラス
AppDomainUnloadedException メンバ
System 名前空間
Exception
その他の技術情報
例外の処理とスロー

AppDomainUnloadedException コンストラクタ (SerializationInfo, StreamingContext)

シリアル化したデータ使用して、AppDomainUnloadedException クラス新しインスタンス初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Protected Sub New ( _
    info As SerializationInfo, _
    context As StreamingContext _
)
Dim info As SerializationInfo
Dim context As StreamingContext

Dim instance As New AppDomainUnloadedException(info,
 context)
protected AppDomainUnloadedException (
    SerializationInfo info,
    StreamingContext context
)
protected:
AppDomainUnloadedException (
    SerializationInfo^ info, 
    StreamingContext context
)
protected AppDomainUnloadedException (
    SerializationInfo info, 
    StreamingContext context
)
protected function AppDomainUnloadedException
 (
    info : SerializationInfo, 
    context : StreamingContext
)

パラメータ

info

シリアル化されたオブジェクト データ保持するオブジェクト

context

転送元または転送先に関すコンテキスト情報

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

AppDomainUnloadedException コンストラクタ

AppDomainUnloadedException クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
AppDomainUnloadedException () AppDomainUnloadedException クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

AppDomainUnloadedException (String) 指定したエラー メッセージ使用してAppDomainUnloadedException クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

AppDomainUnloadedException (SerializationInfo, StreamingContext) シリアル化したデータ使用してAppDomainUnloadedException クラス新しインスタンス初期化します。
AppDomainUnloadedException (String, Exception) 指定したエラー メッセージと、この例外原因である内部例外への参照使用してAppDomainUnloadedException クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

参照参照

関連項目

AppDomainUnloadedException クラス
AppDomainUnloadedException メンバ
System 名前空間

AppDomainUnloadedException コンストラクタ (String)

指定したエラー メッセージ使用して、AppDomainUnloadedException クラス新しインスタンス初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Dim message As String

Dim instance As New AppDomainUnloadedException(message)
public AppDomainUnloadedException (
    string message
)
public:
AppDomainUnloadedException (
    String^ message
)
public AppDomainUnloadedException (
    String message
)
public function AppDomainUnloadedException
 (
    message : String
)

パラメータ

message

エラー説明するメッセージ

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
AppDomainUnloadedException クラス
AppDomainUnloadedException メンバ
System 名前空間

AppDomainUnloadedException プロパティ


パブリック プロパティパブリック プロパティ

プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ HResult  特定の例外割り当てられているコード化数値である HRESULT を取得または設定します。 ( Exception から継承されます。)
参照参照

関連項目

AppDomainUnloadedException クラス
System 名前空間
AppDomain クラス
Exception

その他の技術情報

例外の処理とスロー

AppDomainUnloadedException メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

AppDomainUnloadedException クラス
System 名前空間
AppDomain クラス
Exception

その他の技術情報

例外の処理とスロー

AppDomainUnloadedException メンバ

アンロードされたアプリケーション ドメインアクセスようとするスローされる例外

AppDomainUnloadedException データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
プロテクト コンストラクタプロテクト コンストラクタ
  名前 説明
プロテクト メソッド AppDomainUnloadedException オーバーロードされますAppDomainUnloadedException クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ HResult  特定の例外割り当てられているコード化数値である HRESULT を取得または設定します。(Exception から継承されます。)
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

AppDomainUnloadedException クラス
System 名前空間
AppDomain クラス
Exception

その他の技術情報

例外の処理とスロー



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「AppDomainUnloadedException」の関連用語

AppDomainUnloadedExceptionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



AppDomainUnloadedExceptionのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS