ModuleResolveEventHandler Delegate


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

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 = typeof(MySample).Assembly;
        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 = typeof(MySample).Assembly;
        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
Available since 1.1
Return to top