AppDomainUnloadedException クラス
アセンブリ: mscorlib (mscorlib.dll 内)

<SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public Class AppDomainUnloadedException Inherits SystemException
[SerializableAttribute] [ComVisibleAttribute(true)] public class AppDomainUnloadedException : SystemException
[SerializableAttribute] [ComVisibleAttribute(true)] public ref class AppDomainUnloadedException : public SystemException

.NET Framework Version 2.0 では、ユーザー コード内で処理されない AppDomainUnloadedException は、次のような影響を及ぼします。
-
スレッドがマネージ コード内で開始されている場合、そのスレッドは終了します。未処理の例外は、アプリケーションを終了できません。
-
ThreadPool スレッドでタスクを実行している場合、そのタスクは終了し、スレッドはスレッド プールに返されます。未処理の例外は、アプリケーションを終了できません。
-
メイン アプリケーション スレッドなど、アンマネージ コード内でスレッドを開始している場合、そのスレッドは終了します。未処理の例外は続行でき、オペレーティング システムはアプリケーションを終了します。
AppDomainUnloadedException は、値 0x80131014 を保持する HRESULT COR_E_APPDOMAINUNLOADED を使用します。
AppDomainUnloadedException のインスタンスの初期プロパティ値の一覧については、AppDomainUnloadedException コンストラクタのトピックを参照してください。

このセクションには、2 つのコード例が含まれています。1 つ目の例では、AppDomainUnloadedException がさまざまなスレッドに及ぼす影響を示し、2 つ目の例では、単一のアプリケーション ドメインのアンロードを示します。
アプリケーション ドメインの境界を越えてマーシャリングできる 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() */
アプリケーション ドメインを作成し、アンロードするコード例を次に示します。また、この例では、アンロードされたドメインへのアクセス試行で、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.Exception
System.SystemException
System.AppDomainUnloadedException


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AppDomainUnloadedException コンストラクタ ()
アセンブリ: mscorlib (mscorlib.dll 内)


このコンストラクタは、新しいインスタンスの Message プロパティを初期化し、その値として "対象のアプリケーション ドメインがアンロードされています" などのエラーを説明するシステム提供のメッセージを指定します。このメッセージは、システムの現在のカルチャを考慮して指定します。
AppDomainUnloadedException のインスタンスの初期プロパティ値を次の表に示します。

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AppDomainUnloadedException コンストラクタ (String, Exception)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim message As String Dim innerException As Exception Dim instance As New AppDomainUnloadedException(message, innerException)

message パラメータの内容は、ユーザーが理解できる内容にします。このコンストラクタの呼び出し元は、この文字列が現在のシステムのカルチャに合わせてローカライズ済みであることを確認しておく必要があります。
前の例外の直接の結果としてスローされる例外については、InnerException プロパティに、前の例外への参照が格納されます。InnerException プロパティは、コンストラクタに渡されたものと同じ値を返します。InnerException プロパティによって内部例外値がコンストラクタに渡されなかった場合は、null 参照を返します。
AppDomainUnloadedException のインスタンスの初期プロパティ値を次の表に示します。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AppDomainUnloadedException コンストラクタ (SerializationInfo, StreamingContext)
アセンブリ: mscorlib (mscorlib.dll 内)

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


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AppDomainUnloadedException コンストラクタ

名前 | 説明 |
---|---|
AppDomainUnloadedException () | AppDomainUnloadedException クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
AppDomainUnloadedException (String) | 指定したエラー メッセージを使用して、AppDomainUnloadedException クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
AppDomainUnloadedException (SerializationInfo, StreamingContext) | シリアル化したデータを使用して、AppDomainUnloadedException クラスの新しいインスタンスを初期化します。 |
AppDomainUnloadedException (String, Exception) | 指定したエラー メッセージと、この例外の原因である内部例外への参照を使用して、AppDomainUnloadedException クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |

AppDomainUnloadedException コンストラクタ (String)
アセンブリ: mscorlib (mscorlib.dll 内)


message パラメータの内容は、ユーザーが理解できる内容にします。このコンストラクタの呼び出し元は、この文字列が現在のシステムのカルチャに合わせてローカライズ済みであることを確認しておく必要があります。
AppDomainUnloadedException のインスタンスの初期プロパティ値を次の表に示します。

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AppDomainUnloadedException プロパティ

名前 | 説明 | |
---|---|---|
![]() | Data | 例外に関する追加のユーザー定義情報を提供するキー/値ペアのコレクションを取得します。 ( Exception から継承されます。) |
![]() | HelpLink | 例外に関連付けられているヘルプ ファイルへのリンクを取得または設定します。 ( Exception から継承されます。) |
![]() | InnerException | 現在の例外を発生させた Exception インスタンスを取得します。 ( Exception から継承されます。) |
![]() | Message | 現在の例外を説明するメッセージを取得します。 ( Exception から継承されます。) |
![]() | Source | エラーの原因となったアプリケーションまたはオブジェクトの名前を取得または設定します。 ( Exception から継承されます。) |
![]() | StackTrace | 現在の例外がスローされたときにコール スタックにあったフレームの文字列形式を取得します。 ( Exception から継承されます。) |
![]() | TargetSite | 現在の例外をスローするメソッドを取得します。 ( Exception から継承されます。) |


AppDomainUnloadedException メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetBaseException | 派生クラスでオーバーライドされた場合、それ以後に発生する 1 つ以上の例外の主要な原因である Exception を返します。 ( Exception から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetObjectData | 派生クラスでオーバーライドされた場合は、その例外に関する情報を使用して SerializationInfo を設定します。 ( Exception から継承されます。) |
![]() | GetType | 現在のインスタンスのランタイム型を取得します。 ( Exception から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の例外の文字列形式を作成して返します。 ( Exception から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

AppDomainUnloadedException メンバ
アンロードされたアプリケーション ドメインにアクセスしようとするとスローされる例外。
AppDomainUnloadedException データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | AppDomainUnloadedException | オーバーロードされます。 AppDomainUnloadedException クラスの新しいインスタンスを初期化します。 |


名前 | 説明 | |
---|---|---|
![]() | Data | 例外に関する追加のユーザー定義情報を提供するキー/値ペアのコレクションを取得します。(Exception から継承されます。) |
![]() | HelpLink | 例外に関連付けられているヘルプ ファイルへのリンクを取得または設定します。(Exception から継承されます。) |
![]() | InnerException | 現在の例外を発生させた Exception インスタンスを取得します。(Exception から継承されます。) |
![]() | Message | 現在の例外を説明するメッセージを取得します。(Exception から継承されます。) |
![]() | Source | エラーの原因となったアプリケーションまたはオブジェクトの名前を取得または設定します。(Exception から継承されます。) |
![]() | StackTrace | 現在の例外がスローされたときにコール スタックにあったフレームの文字列形式を取得します。(Exception から継承されます。) |
![]() | TargetSite | 現在の例外をスローするメソッドを取得します。(Exception から継承されます。) |


名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetBaseException | 派生クラスでオーバーライドされた場合、それ以後に発生する 1 つ以上の例外の主要な原因である Exception を返します。 (Exception から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetObjectData | 派生クラスでオーバーライドされた場合は、その例外に関する情報を使用して SerializationInfo を設定します。 (Exception から継承されます。) |
![]() | GetType | 現在のインスタンスのランタイム型を取得します。 (Exception から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の例外の文字列形式を作成して返します。 (Exception から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- AppDomainUnloadedExceptionのページへのリンク