AppDomain.AssemblyLoad Olay

Tanım

Bir derleme yüklendiğinde gerçekleşir.

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

Olay Türü

Uygulamalar

Öznitelikler

Örnekler

Aşağıdaki örnekte olayı gösterilmektedir AssemblyLoad .

Bu kod örneğinin çalışması için, tam derleme adını sağlamanız gerekir. Tam derleme adını alma hakkında bilgi için bkz. Derleme Adları.

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 AssemblyLoadSnippet {

   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();
   }
}
open System

let printLoadedAssemblies (domain: AppDomain) =
    printfn "LOADED ASSEMBLIES:"
    for a in domain.GetAssemblies() do
        printfn $"{a.FullName}"
    printfn ""

let myAssemblyLoadEventHandler _ (args: AssemblyLoadEventArgs)  =
    printfn $"ASSEMBLY LOADED: {args.LoadedAssembly.FullName}\n"

let currentDomain = AppDomain.CurrentDomain
currentDomain.AssemblyLoad.AddHandler(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
Option Strict On
Option Explicit On

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
   
   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
   
   Sub MyAssemblyLoadEventHandler(sender As Object, args As AssemblyLoadEventArgs)
      Console.WriteLine("ASSEMBLY LOADED: " + args.LoadedAssembly.FullName)
      Console.WriteLine()
   End Sub

End Module 'Test

Açıklamalar

AssemblyLoadEventHandler Bu olayın temsilcisi hangi derlemenin yüklendiğini gösterir.

Bu olay için bir olay işleyicisi kaydetmek için gerekli izinlere sahip olmanız gerekir veya bir SecurityException oluşturulur.

Olayları işleme hakkında daha fazla bilgi için bkz. Olayları İşleme ve Oluşturma.

Şunlara uygulanır