I have project called A, located in C:\ProjectA.
It references a dll called B.dll, located in C:\Binaries.
Now B.dll has to dynamicly load a second DLL called C.DLL which is in the same folder (C:\Binaries). But how can B determine C’s location?
I know about AppDomain.CurrentDomain.BaseDirectory and Assembly.GetExecutingAssembly().Location, but both will return ‘C:\ProjectA\’, because B.dll was loaded by A.exe.
I know the obvious solution would be to place all binaries in the same folder, and they will be when released, but while developing I cannot change the repositry’s layout, and I want to avoid to hardcode the paths.
Edit: Sorry duplicate of How do I get the path of the assembly the code is in?
How about using
Assembly.GetCallingAssemblyfrom B? This will return The Assembly object of the method that invoked the currently executing method. (ie B)see also this similar stack overflow question