ModuleResolveEventHandler Delegate

Represents the method that will handle the ModuleResolve event of an Assembly.

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

public delegate Module^ ModuleResolveEventHandler (
	Object^ sender, 
	ResolveEventArgs^ e
/** @delegate */
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public delegate Module ModuleResolveEventHandler (
	Object sender, 
	ResolveEventArgs e
JScript supports the use of delegates, but not the declaration of new ones.



The assembly that was the source of the event.


The arguments supplied by the object describing the event.

When you create an Assembly delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event handler delegates, see Events and Delegates.

If the common language runtime class loader cannot resolve a reference to an internal module of an assembly through normal means, the event is raised to give the callback a chance to find or load the module itself and return it.

Each derived class of Delegate and MulticastDelegate has a constructor and an Invoke method. See the Managed Extensions for C++ code example given in the description for the Delegate.

The following example demonstrates the sequence of execution in which an event handler is called. In this example, Server1 is an external module of the MySample class.

To compile and run the example

Open a Command Prompt window and navigate to the directory that contains MySample.cs.

Compile Server1 using the following command:

csc /out:subfolder\Server1.netmodule /t:module Server1.cs

Compile MySample using the following command:

csc /out:MySample.exe /t:exe /addmodule:subfolder\Server1.netmodule MySample.cs

Run MySample.exe.


The module file Server1.netmodule must be in a subdirectory named "subfolder" for this example to work properly.

using System;
using System.Reflection;
public class Server1 : MarshalByRefObject 
    public int trivial()
        Console.WriteLine ("server1.trivial");
        return 1;
using System;
using System.IO;
using System.Reflection;
class MySample
    public static int Main(String[] args)
        Assembly asm1 = Assembly.GetExecutingAssembly();
        asm1.ModuleResolve += new ModuleResolveEventHandler (evModuleResolve);
        Console.WriteLine("Calling MySample.Test");
        return 0;
    private static Module evModuleResolve(object sender, ResolveEventArgs e)
        FileStream fs = File.Open("subfolder\\Server1.netmodule", FileMode.Open);
        byte [] rgFileBytes = new byte [1];
        long len = fs.Length;
        rgFileBytes = new byte[len];
        fs.Read(rgFileBytes, 0, (int)len);
        Assembly a = Assembly.GetExecutingAssembly();
        Module m = a.LoadModule("Server1.netmodule", rgFileBytes);
        return m;
    private static void Test()
        Console.WriteLine("Instantiating Server1");
        Server1 s = new Server1();
        Console.WriteLine("Calling Server1.trivial");

Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions