Bewerken

Delen via


ModuleResolveEventHandler Delegate

Definition

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

public delegate System::Reflection::Module ^ ModuleResolveEventHandler(System::Object ^ sender, ResolveEventArgs ^ e);
public delegate System.Reflection.Module ModuleResolveEventHandler(object sender, ResolveEventArgs e);
[System.Serializable]
public delegate System.Reflection.Module ModuleResolveEventHandler(object sender, ResolveEventArgs e);
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public delegate System.Reflection.Module ModuleResolveEventHandler(object sender, ResolveEventArgs e);
type ModuleResolveEventHandler = delegate of obj * ResolveEventArgs -> Module
[<System.Serializable>]
type ModuleResolveEventHandler = delegate of obj * ResolveEventArgs -> Module
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ModuleResolveEventHandler = delegate of obj * ResolveEventArgs -> Module
Public Delegate Function ModuleResolveEventHandler(sender As Object, e As ResolveEventArgs) As Module 

Parameters

sender
Object

The assembly that was the source of the event.

e
ResolveEventArgs

The arguments supplied by the object describing the event.

Return Value

The module that satisfies the request.

Attributes

Examples

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.

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...");
        Test();
        return 0;
    }
    private static Module evModuleResolve(object sender, ResolveEventArgs e)
    {
        Console.WriteLine();
        Console.WriteLine("******************************************************");
        Console.WriteLine("* MySample.evModuleResolve() in module: {0:s} *",
            Type.GetType("MySample").Module.ScopeName);
        Console.WriteLine("******************************************************");
        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...");
        s.trivial();
    }
}
// Server1 module

using System;
using System.Reflection;

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

To compile and run the example:

  1. Compile Server1 using the following command:

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

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

Note

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

Remarks

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.

Extension Methods

GetMethodInfo(Delegate)

Gets an object that represents the method represented by the specified delegate.

Applies to