This documentation is archived and is not being maintained.

AppDomain.AssemblyResolve Event

Occurs when the resolution of an assembly fails.

[Visual Basic]
Public Overridable Event AssemblyResolve As ResolveEventHandler
public virtual event ResolveEventHandler AssemblyResolve;
public: virtual __event ResolveEventHandler* AssemblyResolve;

[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.

Event Data

The event handler receives an argument of type ResolveEventArgs containing data related to this event. The following ResolveEventArgs property provides information specific to this event.

Property Description
Name Gets the name of the item to resolve.


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 permissions described in the Permissions section. If you do not have the appropriate permissions, a SecurityException occurs.

For more information about handling events, see Consuming Events.


[Visual Basic, C#, C++] The following sample demonstrates the AssemblyResolve event.

[Visual Basic, C#, C++] 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.

[Visual Basic] 
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)
     ' You must supply a valid fully qualified assembly name here.
         domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType")
      Catch e As Exception
      End Try
   End Sub 'InstantiateMyType
   Function MyResolveEventHandler(sender As Object, args As ResolveEventArgs) As [Assembly]
      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) {
   static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) {
      return typeof(MyType).Assembly;

public __gc class MyType {
   MyType() {
      Console::WriteLine(S"MyType instantiated!");

__gc class Test {
   static void InstantiateMyType(AppDomain* domain) {
      try {
         // You must supply a valid fully qualified assembly name here.
         domain->CreateInstance(S"Assembly text name, Version, Culture, PublicKeyToken", S"MyType");
      } catch (Exception* e) {
   static Assembly* MyResolveEventHandler(Object* sender, ResolveEventArgs* args) {
      return __typeof(MyType)->Assembly;

int main() {
   AppDomain*  currentDomain = AppDomain::CurrentDomain;

   Test::InstantiateMyType(currentDomain);    // Failed!

   currentDomain->AssemblyResolve += new ResolveEventHandler(0, Test::MyResolveEventHandler);

   Test::InstantiateMyType(currentDomain);    // OK!

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

AppDomain Class | AppDomain Members | System Namespace