AppDomain.AssemblyLoad AppDomain.AssemblyLoad AppDomain.AssemblyLoad AppDomain.AssemblyLoad Event

定義

アセンブリが読み込まれたときに発生します。Occurs when an assembly is loaded.

public:
 virtual event AssemblyLoadEventHandler ^ AssemblyLoad;
[add: System.Security.SecurityCritical]
[remove: System.Security.SecurityCritical]
public event AssemblyLoadEventHandler AssemblyLoad;
member this.AssemblyLoad : AssemblyLoadEventHandler 
Public Custom Event AssemblyLoad As AssemblyLoadEventHandler 

実装

属性

次のサンプルでは、AssemblyLoadイベント。The following sample demonstrates the AssemblyLoad event.

このコード例を実行するには、完全修飾アセンブリ名を指定する必要があります。For this code example to run, you must provide the fully qualified assembly name. 完全修飾アセンブリ名を取得する方法については、次を参照してください。アセンブリ名します。For information about how to obtain the fully qualified assembly name, see Assembly Names.

using namespace System;
using namespace System::Reflection;
ref class Test
{
public:
   static void MyAssemblyLoadEventHandler( Object^ sender, AssemblyLoadEventArgs^ args )
   {
      Console::WriteLine( "ASSEMBLY LOADED: {0}", args->LoadedAssembly->FullName );
      Console::WriteLine();
   }

};

void PrintLoadedAssemblies( AppDomain^ domain )
{
   Console::WriteLine( "LOADED ASSEMBLIES:" );
   System::Collections::IEnumerator^ myEnum = domain->GetAssemblies()->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Assembly^ a = safe_cast<Assembly^>(myEnum->Current);
      Console::WriteLine( a->FullName );
   }

   Console::WriteLine();
}

int main()
{
   AppDomain^ currentDomain = AppDomain::CurrentDomain;
   currentDomain->AssemblyLoad += gcnew AssemblyLoadEventHandler( Test::MyAssemblyLoadEventHandler );
   PrintLoadedAssemblies( currentDomain );
   
   // Lists mscorlib and this assembly
   // You must supply a valid fully qualified assembly name here.
   currentDomain->CreateInstance( "System.Windows.Forms, Version, Culture, PublicKeyToken", "System.Windows.Forms.TextBox" );
   
   // Loads System, System::Drawing, System::Windows::Forms
   PrintLoadedAssemblies( currentDomain );
   
   // Lists all five assemblies
}

using System;
using System.Reflection;

class Test {

   public static void Main() {
      AppDomain currentDomain = AppDomain.CurrentDomain;
      currentDomain.AssemblyLoad += new AssemblyLoadEventHandler(MyAssemblyLoadEventHandler);
      
      PrintLoadedAssemblies(currentDomain);
      // Lists mscorlib and this assembly

      // You must supply a valid fully qualified assembly name here.      
      currentDomain.CreateInstance("System.Windows.Forms, Version, Culture, PublicKeyToken", "System.Windows.Forms.TextBox");
      // Loads System, System.Drawing, System.Windows.Forms
      
      PrintLoadedAssemblies(currentDomain);
      // Lists all five assemblies
   }
   
   static void PrintLoadedAssemblies(AppDomain domain) {
      Console.WriteLine("LOADED ASSEMBLIES:");
      foreach (Assembly a in domain.GetAssemblies()) {
         Console.WriteLine(a.FullName);
      }
      Console.WriteLine();
   }
   
   static void MyAssemblyLoadEventHandler(object sender, AssemblyLoadEventArgs args) {
      Console.WriteLine("ASSEMBLY LOADED: " + args.LoadedAssembly.FullName);
      Console.WriteLine();
   }
}
Option Strict On
Option Explicit On

Imports System
Imports System.Reflection

Module Test
   
   Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      AddHandler currentDomain.AssemblyLoad, AddressOf MyAssemblyLoadEventHandler
      
      PrintLoadedAssemblies(currentDomain)
      ' Lists mscorlib and this assembly

      ' You must supply a valid fully qualified assembly name here.      
      currentDomain.CreateInstance("System.Windows.Forms,Version,Culture,PublicKeyToken", "System.Windows.Forms.TextBox")
      ' Loads System, System.Drawing, System.Windows.Forms
      
      PrintLoadedAssemblies(currentDomain)
      ' Lists all five assemblies
   End Sub 'Main
   
   Sub PrintLoadedAssemblies(domain As AppDomain)
      Console.WriteLine("LOADED ASSEMBLIES:")
      Dim a As System.Reflection.Assembly
      For Each a In domain.GetAssemblies()
         Console.WriteLine(a.FullName)
      Next a
      Console.WriteLine()
   End Sub 'PrintLoadedAssemblies
   
   Sub MyAssemblyLoadEventHandler(sender As Object, args As AssemblyLoadEventArgs)
      Console.WriteLine("ASSEMBLY LOADED: " + args.LoadedAssembly.FullName)
      Console.WriteLine()
   End Sub 'MyAssemblyLoadEventHandler

End Module 'Test 

注釈

AssemblyLoadEventHandlerデリゲートに対して、このイベントは、どのようなアセンブリが読み込まれたことを示します。The AssemblyLoadEventHandler delegate for this event indicates what assembly was loaded.

このイベントのイベント ハンドラーを登録するには、必要なアクセス許可が必要またはSecurityExceptionがスローされます。To register an event handler for this event, you must have the required permissions, or a SecurityException is thrown.

イベントの処理の詳細については、「処理とイベントの発生」を参照してください。For more information about handling events, see Handling and Raising Events.

セキュリティ

SecurityCriticalAttribute
直前の呼び出し元に対する完全な信頼が必要です。Requires full trust for the immediate caller. このメンバーは、部分的に信頼されたまたは透過的なコードで使用することはできません。This member cannot be used by partially trusted or transparent code.

適用対象