How do I get the current module?
-
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
. -
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
.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
-
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
. -
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
. -
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
.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 theStackTrace
. -
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?
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;
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[^]
-
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?