다음을 통해 공유


AppDomain.AssemblyResolve 이벤트

어셈블리를 확인하지 못할 경우 발생합니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Event AssemblyResolve As ResolveEventHandler
‘사용 방법
Dim instance As AppDomain
Dim handler As ResolveEventHandler

AddHandler instance.AssemblyResolve, handler
public event ResolveEventHandler AssemblyResolve
public:
virtual event ResolveEventHandler^ AssemblyResolve {
    void add (ResolveEventHandler^ value) sealed;
    void remove (ResolveEventHandler^ value) sealed;
}
/** @event */
public final void add_AssemblyResolve (ResolveEventHandler value)

/** @event */
public final void remove_AssemblyResolve (ResolveEventHandler value)
JScript에서는 이벤트를 사용할 수 있지만 새로 선언할 수는 없습니다.

설명

이 이벤트에서 형식, 어셈블리 또는 리소스를 확인하는 어셈블리를 반환하는 작업은 ResolveEventHandler에서 수행됩니다.

이 이벤트에 대한 이벤트 처리기를 등록하려면 필요한 사용 권한이 있어야 합니다. 그렇지 않으면 SecurityException이 throw됩니다.

이벤트 처리에 대한 자세한 내용은 이벤트 사용을 참조하십시오.

예제

다음 샘플에서는 AssemblyResolve 이벤트에 대해 설명합니다.

이 코드 예제를 실행하려면 정규화된 어셈블리 이름을 사용해야 합니다. 정규화된 어셈블리 이름을 가져오는 방법에 대한 자세한 내용은 어셈블리 이름을 참조하십시오.

Public Class MyType
   
   Public Sub New()
      Console.WriteLine("MyType instantiated!")
   End Sub 'New

End Class 'MyType

Module Test
   
   Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      
      InstantiateMyType(currentDomain)    ' Failed!

      AddHandler currentDomain.AssemblyResolve, AddressOf MyResolveEventHandler
      
      InstantiateMyType(currentDomain)    ' OK!
   End Sub 'Main
   
   Sub InstantiateMyType(domain As AppDomain)
      Try
     ' You must supply a valid fully qualified assembly name here.
         domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType")
      Catch e As Exception
         Console.WriteLine(e.Message)
      End Try
   End Sub 'InstantiateMyType
   
   Function MyResolveEventHandler(sender As Object, args As ResolveEventArgs) As [Assembly]
      Console.WriteLine("Resolving...")
      Return GetType(MyType).Assembly
   End Function 'MyResolveEventHandler

End Module 'Test
public class MyType {
   public MyType() {
      Console.WriteLine("MyType instantiated!");
   }
}

class Test {
   public static void Main() {
      AppDomain currentDomain = AppDomain.CurrentDomain;

      InstantiateMyType(currentDomain);    // Failed!

      currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);

      InstantiateMyType(currentDomain);    // OK!
   }

   static void InstantiateMyType(AppDomain domain) {
      try {
     // You must supply a valid fully qualified assembly name here.
         domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType");
      } catch (Exception e) {
         Console.WriteLine(e.Message);
      }
   }
   
   static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) {
      Console.WriteLine("Resolving...");
      return typeof(MyType).Assembly;
   }
}
public ref class MyType
{
public:
   MyType()
   {
      Console::WriteLine( "MyType instantiated!" );
   }

};

ref class Test
{
public:
   static void InstantiateMyType( AppDomain^ domain )
   {
      try
      {
         // You must supply a valid fully qualified assembly name here.
         domain->CreateInstance( "Assembly text name, Version, Culture, PublicKeyToken", "MyType" );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( e->Message );
      }
   }

   static Assembly^ MyResolveEventHandler( Object^ sender, ResolveEventArgs^ args )
   {
      Console::WriteLine( "Resolving..." );
      return MyType::typeid->Assembly;
   }
};

int main()
{
   AppDomain^ currentDomain = AppDomain::CurrentDomain;
   Test::InstantiateMyType( currentDomain ); // Failed!
   currentDomain->AssemblyResolve += gcnew ResolveEventHandler( Test::MyResolveEventHandler );
   Test::InstantiateMyType( currentDomain ); // OK!
}

.NET Framework 보안

플랫폼

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에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

AppDomain 클래스
AppDomain 멤버
System 네임스페이스