6

I understand that an Assembly is made of 1 or more modules, and resource files if any.

If you compile a project in C#, then the compiler will simply turn the code into a managed module, and then throw that module into an assembly. Now my question is, when would an Assembly have more than 1 managed module?

ebb
  • 9,297
  • 18
  • 72
  • 123
  • When you say "module", what do you mean? – Oded Sep 14 '11 at 11:57
  • @Oded, by module I mean "managed module", which is the IL code and metadata made up by the compiler targeting CLR. – ebb Sep 14 '11 at 12:00
  • Have you read this? http://stackoverflow.com/questions/1326556/what-is-managed-module/1326563#1326563 – Oded Sep 14 '11 at 12:01
  • @Oded, yea.. I've read that. I do understand what a managed module is, and what an assemly is etc. But what I dont understand is that assemblies can have multiple managed modules. When would an assembly have more than 1 managed module? – ebb Sep 14 '11 at 12:38
  • 1
    I've gone quiet as I don't have an answer for you... – Oded Sep 14 '11 at 12:59

2 Answers2

4

Heres a good explanation of that Netmodule vs. Assembly.

In short, one would use multiple modules for these reasons:

Multi-language assemblies.

If the assembly is consist of source files with different programming languages, you have to compile files with the same programming languages into netmodules, then link them into assemblies.

Separately maintained source files.

If the assembly is maintained by multiple developers, it may make sense to separate the source files into small collections. Each collection is owned by an individual developer. Collections are compiled as netmodules, then linked to the final assembly.

Small download footprint.

If the assembly is hosted in an http site, CLR will only download the main module at the first time. The remaining modules will be downloaded on demand. You can separate the less frequently used code from the main line code, and compiled the less frequently used code as a netmodule. User will only download the netmodule when it is needed.

Link the same source files into multiple assemblies.

You may have some common code that is used in multiple assemblies. The common code is small enough that it is not worth to compile them into a separate assembly. To avoid compiling the same source files multiple times, you can compile them into a netmodule, then link it into different assemblies.

L.E.O
  • 1,069
  • 1
  • 13
  • 28
  • The link is dead, here is the current one: https://learn.microsoft.com/en-us/archive/blogs/junfeng/netmodule-vs-assembly – Tejes Jul 20 '23 at 14:34
-4

If you have a class in a Project namespace, and another class in a Project.Utilities namespace, there would be two modules:

  • Project
  • Project.Utilities

This seems to be the way that the .Net assembly is organised, classes -> modules -> assembly.

The compiler seems to name modules by the namespaces the classes are in.

You can see the module structure in existing assemblies by using ildasm or .Net Reflector

Darkzaelus
  • 2,059
  • 1
  • 15
  • 31