Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 641
  • Last Modified:

Get Module of class library

I need to find Module reference of class library where code is executed.
For example, Assembly.GetExecutingAssembly.GetModules gives list of all modules in the current process, and I need only current Dll module.
  • 2
1 Solution
Hello AlexFM,

there is a way shown here to get the current module, but the way they do it is maybe not what you're after
source: http://msdn2.microsoft.com/en-us/library/system.reflection.module.aspx

declare a empty class in your class file
class Class1 {

and use that to reflect on the module
Class1 c1 = new Class1();
//  Show the current module.
Module m = c1.GetType().Module;

sharing what you know, learning what you don't
AlexFMAuthor Commented:
Nice, thank you. I think this can be done in any instance function place by the following way: Module m = this.GetType().Module;
I need this to get unmanaged HNODULE handle in C++/CLI project. I will test this code later when C++ code will be ready.
that is the big difference between you and me, i need to learn a lot seeing that this is the same as the current class :)

since i was curious what would happen actually used it on the curAssembly like
curAssembly.GetType().Module which came back with mscorlib.dll


this.GetType().Module gave the name of the module as you said

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now