0

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?

NZJames
  • 4,963
  • 15
  • 50
  • 100
  • 4
    Possible duplicate of [How do I get the path of the assembly the code is in?](http://stackoverflow.com/questions/52797/how-do-i-get-the-path-of-the-assembly-the-code-is-in) – thehennyy Jul 06 '16 at 11:12
  • That talks about GetExecutingAssembly which is not what I want. – NZJames Jul 06 '16 at 11:18
  • You can use this approach on any `Assembly` object. It does not matter where you got it from. – thehennyy Jul 06 '16 at 11:19

2 Answers2

0

I use this way to get the current class's assembly path:

var dllPath = new Uri(this.GetType().Assembly.GetName().CodeBase).LocalPath;
Stephen Zeng
  • 2,748
  • 21
  • 18
0

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

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