O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

16.4. Retrieving modules from an assembly

An assembly can consist of one or more modules.[1] To obtain an array of modules in an assembly, you use System.Reflection.Assembly's GetModules method.

[1] A module is a file containing IL codes but without a manifest. Each assembly must have one and only one manifest file regardless of the number of modules it contains.

Let's create an assembly (called Assm) containing two modules (Mod1 and Mod2) first. The following three code fragments do just that.

1: // Mod1.cs
2: public class Mod1{}
1: // Mod2.cs
2: public class Mod2{}
 1: // Assm.cs
 2: using System;
 3: using System.Reflection;
 4:
 5: public class Assm{
 6:   public static void Main(){
 7:     Assembly a = Assembly.LoadFrom("Assm.exe");
 8:     Module[] modules ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required