简体   繁体   中英

How to get current physical path of a reflected assembly

I have an executable that loads another class library DLL using reflection. Within that class library, I want to find out what the physical path of the class library is. I don't want the executing assembly, as that is the original executable.

Eg the exe might be in c:\\program\\ and the class library might be c:\\libraries\\remote\\Assembly1.dll

Within a method inside Assembly1.dll I need to call something that returns me

c:\\libraries\\remote\\

I have tried

  var currentLocation = Assembly.GetAssembly(GetType()).Location;

But that doesn't seem to work. How can I do this?

我使用这种方法来获取当前类的汇编路径:

var dllPath = new Uri(this.GetType().Assembly.GetName().CodeBase).LocalPath;

Here's one way I do it. "assembly" is the loaded dll

assembly.Location.Replace(assembly.GetName().Name + ".dll", "")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM