Get Module of class library

Posted on 2006-05-23
Last Modified: 2010-05-18
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.
Question by:AlexFM
    LVL 44

    Accepted 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

    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
    LVL 48

    Author Comment

    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.
    LVL 44

    Expert Comment

    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now