Retrieving path of executing assembly

  • Thread starter Thread starter SLE
  • Start date Start date
S

SLE

Hi there,

We have a class method which is invoked through Remoting/IIS. Within this
class method, we need to get the physical path of the assembly (dll) in
which the method is executing. we have tried:

1) System.Reflection.Assembly.GetExecutingAssembly().Location.ToString()
returns a temporary path, i.e.
c:\windows\microsoft.net\framework\v1.1.4322\temporary asp.net
files\cm.processing\2cff4017\312000e7\assembly\dl2\e92f2bc0\ede223a1_c797c30
1\assembly.dll

2) System.IO.Path.GetFullPath(".")
returns c:\windows\system32\inetsrv


Any clues?

Thanks.
 
There is nothing strange. The Assembly.Location returns where the assembly
was, and "." is the current path of the process. They are entirly different
things. Just like cmd.exe is installed in windows directory, but the
current path could be "c:\".

If you want the physical path of the dll, you might want the first one.
 
Lifeng Lu said:
There is nothing strange. The Assembly.Location returns where the assembly
was, and "." is the current path of the process. They are entirly different
things. Just like cmd.exe is installed in windows directory, but the
current path could be "c:\".

If you want the physical path of the dll, you might want the first one.

Who said there is something strange? Fact is I need a way to get the
_original_ location within the code of an assembly and not the _actual_
location.

We have found the following (3th) way:

Dim assemblyPath As String =
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssem
bly().CodeBase)

If assemblyPath.Substring(0, 6).ToLower() = "file:\" Then
assemblyPath = assemblyPath.Substring(6)
End If


.... which works fine.
 
Back
Top