AppDomain::AssemblyLoad Event

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Occurs when an assembly is loaded.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public:
event AssemblyLoadEventHandler^ AssemblyLoad {
	virtual void add(AssemblyLoadEventHandler^ value) sealed;
	virtual void remove(AssemblyLoadEventHandler^ value) sealed;
}

The AssemblyLoadEventHandler delegate for this event indicates what assembly was loaded.

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.

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
}

SecurityCriticalAttribute

Requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

.NET Framework
Available since 1.1
Return to top
Show: