AppDomainUnloadedException 클래스

정의

언로드된 애플리케이션 도메인에 액세스할 때 throw되는 예외입니다.

public ref class AppDomainUnloadedException : SystemException
public class AppDomainUnloadedException : SystemException
[System.Serializable]
public class AppDomainUnloadedException : SystemException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class AppDomainUnloadedException : SystemException
type AppDomainUnloadedException = class
    inherit SystemException
[<System.Serializable>]
type AppDomainUnloadedException = class
    inherit SystemException
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type AppDomainUnloadedException = class
    inherit SystemException
Public Class AppDomainUnloadedException
Inherits SystemException
상속
AppDomainUnloadedException
특성

예제

이 섹션에는 두 코드 예제가 있습니다. 첫 번째 예의 결과 보여 줍니다.는 AppDomainUnloadedException 에 다양 한 스레드를 두 번째 표시 기본 애플리케이션 도메인 언로드 합니다.

예 1

다음 코드 예제에서는 정의 TestClass 애플리케이션 도메인 경계를 넘어 마샬링될 수 있는 클래스 및 Example 클래스를 포함 하는 static (Shared Visual basic에서) ThreadProc 메서드. ThreadProc 메서드는 애플리케이션 도메인을 만듭니다는 TestClass 도메인의 개체의 메서드를 호출 하 고 TestClass 실행 도메인을 언로드하는 일으키는 AppDomainUnloadedException합니다.

TestClass 메서드는 예외 처리 하지 않고 실행 되는 ThreadPool 스레드 및 태스크 또는 스레드 하지만 애플리케이션이 아니라 처리 되지 않은 예외가 종료는 데모를 일반 스레드에서 합니다. 그런 다음 예외는 해당 애플리케이션을 종료 되지 않은 경우를 보여 주는 기본 애플리케이션 스레드에서 처리 하지 않고 사용 하 여 실행 됩니다.

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()
 */
open System
open System.Threading

// TestClass derives from MarshalByRefObject, so it can be marshaled
// across application domain boundaries.
type TestClass() =
    inherit MarshalByRefObject()
    member _.UnloadCurrentDomain (state: obj) =
        printfn $"\nUnloading the current AppDomain{state}."

        // Unload the current application domain. This causes
        // an AppDomainUnloadedException to be thrown.
        //
        AppDomain.Unload AppDomain.CurrentDomain

let threadProc (state: obj) =
    // 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.
    let ad = AppDomain.CreateDomain "TestDomain"
    let tc = ad.CreateInstanceAndUnwrap("Sample", "TestClass") :?> 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

    printfn "ThreadProc: This message is never displayed."

// 1. Queue ThreadProc as a task for a ThreadPool thread.
ThreadPool.QueueUserWorkItem(threadProc, " from a ThreadPool thread") |> ignore
Thread.Sleep 1000

// 2. Execute ThreadProc on an ordinary thread.
let t = Thread(ParameterizedThreadStart 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)"
with :? AppDomainUnloadedException as adue ->
    printfn $"Main thread caught AppDomainUnloadedException: {adue.Message}"

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

printfn "Main: This message is never displayed."

(* 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()
 *)
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()
'

예제 2

다음 코드 예제에서는 애플리케이션 도메인을 언로드합니다 및 함을 만듭니다는 AppDomainUnloadedException 언로드된 도메인에 액세스 하려고 하는 후속 throw 됩니다.

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." );
   }

}
using System;
using System.Reflection;
using System.Security.Policy;
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.");
        }
    }
}
open System

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

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

printfn $"Host domain: {AppDomain.CurrentDomain.FriendlyName}"
printfn $"child domain: {domain.FriendlyName}"
// Unload the application domain.
AppDomain.Unload domain

try
    printfn ""
    // Note that the following statement creates an exception because the domain no longer exists.
    printfn $"child domain: {domain.FriendlyName}"

with :? AppDomainUnloadedException ->
    printfn "The appdomain MyDomain does not exist."
Imports System.Reflection
Imports System.Security.Policy

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
End Class

설명

.NET Framework 버전 2.0 AppDomainUnloadedException 에서는 사용자 코드에서 처리되지 않는 효과가 다음과 같습니다.

  • 관리 코드에서 스레드가 시작된 경우 종료됩니다. 처리 되지 않은 예외는 애플리케이션을 종료할 수 없습니다.

  • 태스크가 스레드에서 ThreadPool 실행되는 경우 작업이 종료되고 스레드가 스레드 풀로 반환됩니다. 처리 되지 않은 예외는 애플리케이션을 종료할 수 없습니다.

  • 기본 애플리케이션 스레드 등의 비관리 코드에서 스레드가 시작 하는 경우 종료 됩니다. 처리 되지 않은 예외가 계속 진행 하도록 허용 된 및 운영 체제 애플리케이션을 종료 합니다.

AppDomainUnloadedException 는 값이 0x80131014 HRESULT COR_E_APPDOMAINUNLOADED 사용합니다.

인스턴스의 초기 속성 값의 목록을 AppDomainUnloadedException, 참조는 AppDomainUnloadedException 생성자입니다.

생성자

AppDomainUnloadedException()

AppDomainUnloadedException 클래스의 새 인스턴스를 초기화합니다.

AppDomainUnloadedException(SerializationInfo, StreamingContext)

serialize된 데이터를 사용하여 AppDomainUnloadedException 클래스의 새 인스턴스를 초기화합니다.

AppDomainUnloadedException(String)

지정된 오류 메시지를 사용하여 AppDomainUnloadedException 클래스의 새 인스턴스를 초기화합니다.

AppDomainUnloadedException(String, Exception)

지정된 오류 메시지와 해당 예외의 원인인 내부 예외에 대한 참조를 사용하여 AppDomainUnloadedException 클래스의 새 인스턴스를 초기화합니다.

속성

Data

예외에 대한 사용자 정의 정보를 추가로 제공하는 키/값 쌍 컬렉션을 가져옵니다.

(다음에서 상속됨 Exception)
HelpLink

이 예외와 연결된 도움말 파일에 대한 링크를 가져오거나 설정합니다.

(다음에서 상속됨 Exception)
HResult

특정 예외에 할당된 코드화된 숫자 값인 HRESULT를 가져오거나 설정합니다.

(다음에서 상속됨 Exception)
InnerException

현재 예외를 발생시킨 Exception 인스턴스를 가져옵니다.

(다음에서 상속됨 Exception)
Message

현재 예외를 설명하는 메시지를 가져옵니다.

(다음에서 상속됨 Exception)
Source

오류를 발생시키는 애플리케이션 또는 개체의 이름을 가져오거나 설정합니다.

(다음에서 상속됨 Exception)
StackTrace

호출 스택의 직접 실행 프레임 문자열 표현을 가져옵니다.

(다음에서 상속됨 Exception)
TargetSite

현재 예외를 throw하는 메서드를 가져옵니다.

(다음에서 상속됨 Exception)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetBaseException()

파생 클래스에서 재정의된 경우 하나 이상의 후속 예외의 근본 원인이 되는 Exception 을 반환합니다.

(다음에서 상속됨 Exception)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetObjectData(SerializationInfo, StreamingContext)

파생 클래스에서 재정의된 경우 예외에 관한 정보를 SerializationInfo 에 설정합니다.

(다음에서 상속됨 Exception)
GetType()

현재 인스턴스의 런타임 형식을 가져옵니다.

(다음에서 상속됨 Exception)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 예외에 대한 문자열 표현을 만들고 반환합니다.

(다음에서 상속됨 Exception)

이벤트

SerializeObjectState
사용되지 않습니다.

예외에 대한 serialize된 데이터가 들어 있는 예외 상태 개체가 만들어지도록 예외가 serialize될 때 발생합니다.

(다음에서 상속됨 Exception)

적용 대상

추가 정보