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 ?
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.
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.
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]
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.
You can do this using:
string file = (new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).LocalPath;
The Location of the assembly changes based on redirects and shadow copy. Try using the Codebase property instead.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With