1

I have searched the forum and a lot of answers for the above question exist. However, in my case I am referencing a dll from a Plug-In for a Software. It seems like this makes the situation more complicated and none of the solutions I found are returning the proper location.

I tried the following:

Print(AppDomain.CurrentDomain.BaseDirectory); // returns C:\Program Files\TheOtherSoftware\System\
System.Type MyDLLsNameType = null;
Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
foreach (AssemblyName an in a.GetReferencedAssemblies() )
{
  Print(an.Name); // finds various names including MyDLLsName
  Print(an.CodeBase);  // this is null
  if (an.Name == "MyDLLsName"){
    MyDLLsNameType = an.GetType();
  }
}
Print(System.Reflection.Assembly.GetAssembly(MyDLLsNameType).Location); // this returns  "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll"

As a side note: I want to do this because I want to get rid of various absolute paths that required the user to install the software in a specific location. The software even broke when the root drive was not named "C". Given the fact that I don't have much experience in coding it would be great to hear some advice on how to deal with something like that in general.

harold
  • 61,398
  • 6
  • 86
  • 164
timkado
  • 1,922
  • 2
  • 17
  • 27
  • Not saying this is an exact duplicate, but surely one of the follow link answers your question: http://stackoverflow.com/questions/4764680/how-to-get-the-location-of-the-dll-currently-executing – FrostyFire Feb 03 '13 at 20:46
  • Thanks for your comment - If I understand correctly System.Reflection.Assembly.GetAssembly(MyDLLsNameType).Location should return what I want - however it returns the mscorlib.dll location – timkado Feb 03 '13 at 20:51
  • No your wrong I think. Since its a addin you need to do things differently to get what you want. Read all the answers and comments from the above link. The reason I'm not posting an answer is cause I don't know enough to show any code. – FrostyFire Feb 03 '13 at 20:55

0 Answers0