Assembly.GetModules Method ()

Gets all the modules that are part of this assembly.

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

public Module[] GetModules ()
public final Module[] GetModules ()
public final function GetModules () : Module[]

Return Value

An array of modules.

Exception typeCondition


The module to be loaded does not specify a file name extension.

This method works on public and private resource files.


Modules must be emitted with file name extensions.

The following example displays the name of the module in the returned array that contains the assembly manifest.

using System;
using System.Reflection;

public class Form1
    public static void Main()
        Assembly mainAssembly = Assembly.GetExecutingAssembly();
        Console.WriteLine("The executing assembly is {0}.", mainAssembly);
        Module[] mods = mainAssembly.GetModules();
        Console.WriteLine("\tModules in the assembly:");
        foreach (Module m in mods)
            Console.WriteLine("\t{0}", m);

import System.*;
import System.Reflection.*;

public class Form1
    public static void main(String[] args)
        Assembly mainAssembly = Assembly.GetExecutingAssembly();
        Module mainMod = mainAssembly.GetModules()[0];
        Console.WriteLine("The executing assembly is {0}.", mainAssembly);
    } //main
} //Form1

var mainAssembly : Assembly = Assembly.GetExecutingAssembly();
var mainMod : Module = mainAssembly.GetModules()[0];
Console.WriteLine("Module name: {0}", mainMod.Name);

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

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions