Finding the location of a .NET module
A quick pre-Thanksgiving tip that came from an internal discussion today: how to find the location of a .NET module (meaning the currently executing assembly).
Two techniques were identified:
- Identify the current assembly by asking where one of its types is defined
- Use the Assembly.GetExecutingAssembly() to get the assembly from where the current code is executing
Here's the C# code showing the two techniques:
public class AssemblyCmds
public void GetModuleLocation()
Editor ed =
// First technique
Type type = typeof(AssemblyCmds);
Assembly asm1 = type.Assembly;
"\nAssembly location (1) is: "
// Second technique
Assembly asm2 = Assembly.GetExecutingAssembly();
"\nAssembly location (2) is: "
And here are the results, just to show they return the same thing:
Assembly location (1) is: C:\temp\MyAssembly.dll
Assembly location (2) is: C:\temp\MyAssembly.dll