I am writing a .NET library that for various reasons cannot be registered in the GAC. This dll (let’s call it SDK.dll) depends on other DLLs in order to be loaded.
When writing a program that uses this SDK.dll, I noticed that my program failed loading the dll with a FileNotFoundException thrown. This happens because although I was able to find the referenced SDK.dll, the CLR failed to load its dependencies.
The only way I found to solve the problem is to ‘Copy Local’ the SDK.dll and all its dependencies (something I can’t do because of deployment problems), or compiling my program into the same directory as SDK.dll
Is there a way to tell SDK.dll where to look for it’s dependencies regardless of its location? Maybe a SDK.dll.config file can help?
You can handle this at runtime by subscribing to this event:
It’s fired when the runtime fails to resolve an assembly. In your event handler method, write your logic to find the assembly and load it using Assembly.LoadFrom(). It would look something like this: