This documentation is archived and is not being maintained.

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


Type: System.Object
The assembly that was the source of the event.
Type: System.ResolveEventArgs
The arguments supplied by the object describing the event.

Return Value

Type: System.Reflection.Module
The module that satisfies the request.

If the common language runtime class loader cannot resolve a reference to an internal module of an assembly through normal means, this event is raised. The event handler for this delegate must locate and return a module that satisfies the request.

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

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

  2. Compile Server1 using the following command:

    csc /out:subfolder\Server1.netmodule /t:module Server1.cs
  3. Compile MySample using the following command:

    csc /out:MySample.exe /t:exe /addmodule:subfolder\Server1.netmodule MySample.cs
  4. 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.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)
        Console.WriteLine("* MySample.evModuleResolve() in module: {0:s} *",
        FileStream fs = File.Open("subfolder\\Server1.netmodule", FileMode.Open);
        long len = fs.Length;
        byte[] 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...");


// Server1 module

using System;
using System.Reflection;

public class Server1 : MarshalByRefObject
    public int trivial()
        Console.WriteLine("*   Server1.trivial() in module: {0:s}   *", this.GetType().Module.ScopeName);
        Console.WriteLine("Returning from Server1.trivial...");
        return 1;

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.