Learn how to a build a cloud-first strategyRegister Now

x
  • 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.
0
AlexFM
Asked:
AlexFM
  • 2
1 Solution
 
bruintjeCommented:
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;

--------
bruintje
sharing what you know, learning what you don't
0
 
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.
0
 
bruintjeCommented:
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

and

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

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