Microsoft Docs

System.Reflection.ModuleHandle Class

Public struct

Definition

A handle that provides access to metadata for a module. It can be used to obtain a Module instance that represents the module.

Syntax

public struct ModuleHandle

Properties

PropertyTypeDescription
Value IntPtr Gets the internal pointer to the module.

Methods

MethodSignatureDescription
GetModule Module GetModule() Returns the Module represented by this handle.
GetObjectData void GetObjectData(SerializationInfo info, StreamingContext context) Implements ISerializable to serialize the handle.
Equals bool Equals(ModuleHandle handle) Determines whether two ModuleHandle instances are equal.
GetHashCode int GetHashCode() Returns a hash code for this instance.

Examples

Retrieve a ModuleHandle for the currently executing assembly and get its Module object.

using System;
using System.Reflection;

class Demo
{
    static void Main()
    {
        // Obtain a module handle from a type
        ModuleHandle handle = typeof(Demo).Module.ModuleHandle;

        // Convert the handle to a Module instance
        Module module = handle.GetModule();

        Console.WriteLine($"Module Name: {module.Name}");
        Console.WriteLine($"Fully Qualified Name: {module.FullyQualifiedName}");
        Console.WriteLine($"Metadata Token: 0x{module.MetadataToken:X8}");
    }
}

Remarks

ModuleHandle is a low‑level representation of a module and does not expose the full reflection API. Use Module for richer introspection. The handle can be persisted across AppDomain boundaries but should be revalidated using GetModule before usage.