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.