Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. How do I get the current module?

How do I get the current module?

Scheduled Pinned Locked Moved .NET (Core and Framework)
questiontutorial
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JoeRip
    wrote on last edited by
    #1

    I need to know the name of the module (or assembly) which is currently executing my code. ie, if application X has loaded DLL Y, and DLL Y calls a callback method in application X, I want to get the name of DLL Y. I can figure out how to get the name of the MainModule for the current process, or even the list of modules that are loaded for the current process, but I can't figure out how to get the currently executing module from this.

    L J A B 4 Replies Last reply
    0
    • J JoeRip

      I need to know the name of the module (or assembly) which is currently executing my code. ie, if application X has loaded DLL Y, and DLL Y calls a callback method in application X, I want to get the name of DLL Y. I can figure out how to get the name of the MainModule for the current process, or even the list of modules that are loaded for the current process, but I can't figure out how to get the currently executing module from this.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Maybe this will help? http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getexecutingassembly.aspx[^]

      Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Please stand in front of my pistol, smile and wait for the flash - JSOP 2012

      1 Reply Last reply
      0
      • J JoeRip

        I need to know the name of the module (or assembly) which is currently executing my code. ie, if application X has loaded DLL Y, and DLL Y calls a callback method in application X, I want to get the name of DLL Y. I can figure out how to get the name of the MainModule for the current process, or even the list of modules that are loaded for the current process, but I can't figure out how to get the currently executing module from this.

        J Offline
        J Offline
        JoeRip
        wrote on last edited by
        #3

        Hmm... okay, I found Assembly.GetExecutingAssembly. Now I need to determine if I need the assembly name or the module name... what is the difference between a module and an assembly?

        L P 2 Replies Last reply
        0
        • J JoeRip

          I need to know the name of the module (or assembly) which is currently executing my code. ie, if application X has loaded DLL Y, and DLL Y calls a callback method in application X, I want to get the name of DLL Y. I can figure out how to get the name of the MainModule for the current process, or even the list of modules that are loaded for the current process, but I can't figure out how to get the currently executing module from this.

          A Offline
          A Offline
          Abhinav S
          wrote on last edited by
          #4

          Try GetType(). Object.GetType()[^] should give you the appropriate results.

          A new Windows Phone App - Speed Dial

          1 Reply Last reply
          0
          • J JoeRip

            I need to know the name of the module (or assembly) which is currently executing my code. ie, if application X has loaded DLL Y, and DLL Y calls a callback method in application X, I want to get the name of DLL Y. I can figure out how to get the name of the MainModule for the current process, or even the list of modules that are loaded for the current process, but I can't figure out how to get the currently executing module from this.

            B Offline
            B Offline
            Bernhard Hiller
            wrote on last edited by
            #5

            In that moment, it is again application X which is executing, not Dll Y. I do not understand what are trying to achieve, i.e. the objective behind finding out that a function was called from Y. In case that the callback method is an event handler, you could use the "sender" parameter to get more information on the origin. Another possibility is the StackTrace.

            1 Reply Last reply
            0
            • J JoeRip

              Hmm... okay, I found Assembly.GetExecutingAssembly. Now I need to determine if I need the assembly name or the module name... what is the difference between a module and an assembly?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              JoeRip wrote:

              what is the difference between a module and an assembly?

              You're missing the question-icon, most forum-members will assume it's an answer to the original question and skip reading the post. To answer;

              MSDN states[^]:

              A module is a portable executable file, such as type.dll or application.exe, consisting of one or more classes and interfaces. There may be multiple namespaces contained in a single module, and a namespace may span multiple modules.

              In short, an assembly can contain multiple modules (not to be confused with the VB.NET concept of a Module, which is a static class). The code below shows an example of how to use the StackTrace-class, as proposed by another poster;

              Dim mod = New System.Diagnostics.StackTrace().GetFrame(0).GetMethod()
              Console.WriteLine (mod.Module)
              Console.WriteLine (mod.Name)

              Hope this helps a bit :)

              Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

              1 Reply Last reply
              0
              • J JoeRip

                Hmm... okay, I found Assembly.GetExecutingAssembly. Now I need to determine if I need the assembly name or the module name... what is the difference between a module and an assembly?

                P Offline
                P Offline
                pt1401
                wrote on last edited by
                #7

                You probably don't need to use GetModule() or GetAssembly() methods Try the FullName property...

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups