AppDomain.AssemblyResolve Event
Assembly: mscorlib (in mscorlib.dll)
'Declaration Public Event AssemblyResolve As ResolveEventHandler 'Usage Dim instance As AppDomain Dim handler As ResolveEventHandler AddHandler instance.AssemblyResolve, handler
/** @event */ public final void add_AssemblyResolve (ResolveEventHandler value) /** @event */ public final void remove_AssemblyResolve (ResolveEventHandler value)
In JScript, you can handle the events defined by a class, but you cannot define your own.
Not applicable.
For this event, the ResolveEventArgs.Name property returns the assembly name before policy is applied.
It is the responsibility of ResolveEventHandler for this event to return the assembly that resolves the type, assembly, or resource.
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 Events Overview.
The following sample demonstrates the AssemblyResolve 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.
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
- SecurityPermission to add an event handler for this event. Associated enumeration: SecurityPermissionFlag.ControlAppDomain. Security action: LinkDemand.
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.