views:

1842

answers:

2

I have a managed DLL (written in C++/CLI) that contains a class used by a C# executable. In the constructor of the class, I need to get access to the full path of the executable referencing the DLL. In the actual app I know I can use the Application object to do this, but how can I do it from a managed DLL?

+9  A: 
Assembly.GetCallingAssembly()

or

Assembly.GetExecutingAssembly()

or

Assembly.GetEntryAssembly()

Depending on your need.

Then use Location or CodeBase property (I never remember which one).

leppie
Use the CodeBase property after calling one of these methods.
dgvid
+2  A: 

@leppie: Thanks - that was the pointer I needed.

For future reference, in C++/CLI this is the actual syntax that works:

String^ appPathString = Assembly::GetEntryAssembly()->Location;

GetExecutingAssembly() provided the name of the DLL

GetCallingAssembly() returned something like System.Windows.Forms

GetEntryAssembly returned the full path, similar to GetModulePath() under Win32.

Brian Stewart