Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the Assembly path C#

Im trying to know the path of a dll.... several sites says that ive to use System.Reflection.Assembly.GetExecutingAssembly().Location BUT it returns a path in C:\Windows\Microsoft.Net ... etc... \File.Dll

and i want c:\MyProyect\MiWeb\Bin\File.Dll

any help ?

like image 786
jmpena Avatar asked May 27 '09 17:05

jmpena


People also ask

How do you access the assembly of a running application?

The recommended way to retrieve an Assembly object that represents the current assembly is to use the Type. Assembly property of a type found in the assembly, as the following example illustrates. To get the assembly that contains the method that called the currently executing code, use GetCallingAssembly.

What is the method to load assembly by name?

Loads an assembly given its AssemblyName. The assembly is loaded into the domain of the caller using the supplied evidence. Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly. The assembly is loaded into the application domain of the caller.

What is System reflection assembly?

Namespace: System.Reflection. Summary. Defines an Assembly, which is a reusable, versionable, and self-describing building block of a common language runtime application. C# Syntax: [Serializable]

What is C# assembly?

C# Assembly is a standard library developed for . NET. Common Language Runtime, CLR, MSIL, Microsoft Intermediate Language, Just In Time Compilers, JIT, Framework Class Library, FCL, Common Language Specification, CLS, Common Type System, CTS, Garbage Collector, GC.


3 Answers

You can do this using:

string file = (new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).LocalPath;
like image 143
Reed Copsey Avatar answered Nov 15 '22 23:11

Reed Copsey


The Location of the assembly changes based on redirects and shadow copy. Try using the Codebase property instead.

like image 35
Paul Alexander Avatar answered Nov 15 '22 23:11

Paul Alexander


That may actually be the path the program is using... IIRC, It starts out searching for the method call in the GAC before defaulting to the working directory.

like image 31
Ian Jacobs Avatar answered Nov 15 '22 22:11

Ian Jacobs