Reputation: 1459
I have the following situation: I have a windows service that loads many external .dlls as AddIns using the Microsoft AddIn Framework. The AddIn .dlls are each in their own directory inside a 'AddIns' directory that is located in the directory containing the service exe. Every AddIn .dll references a common assembly that is basically an API for the AddIns. I put this in the service directory. The problem I am having is that the API .dll must be in every AddIn directory also or I get the error:
Exception has been thrown by the target of an invocation. - System.IO.FileNotFoundException: Could not load file or assembly 'OSAE.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
I have also tried add this assembly to the GAC which seems to put it at C:\Windows\Microsoft.NET\assembly\GAC_MSIL\OSAE.API\v4.0_1.0.0.0__f47a6446f36f79f7
, but this doesn't seem to help.
How can I either tell the AddIns to look in a specific directory for the assembly or set it up where it is globally accessible somehow?
Upvotes: 1
Views: 9393
Reputation: 4395
I solved it changing my project target platform from Any Cpu to x86. This option is located in Project > Properties > Build. For more information, refer to Microsoft's library BadImageFormatException
Upvotes: 2
Reputation: 8880
Why not load the API.dll manually before you load each add-in DLL. If the add-in DLLs are loading into their own app domain, then you would have to load API.dll into each app domain also. If they are loading into the same app domain, then you wouldl only need to load API.dll once.
Upvotes: 0
Reputation: 1807
I think you problen is already solved at: C# can't find assembly which is already loaded
Take a look at my answer i think it would also fit for your problem!
Upvotes: 1
Reputation: 498904
Use the assembly binding log viewer (Fuslogvw.exe) to see what the runtime is trying to load and where it fails.
The Assembly Binding Log Viewer displays details for assembly binds. This information helps you diagnose why the .NET Framework cannot locate an assembly at run time. These failures are usually the result of an assembly deployed to the wrong location, a native image that is no longer valid, or a mismatch in version numbers or cultures. The common language runtime's failure to locate an assembly typically shows up as a TypeLoadException in your application.
(emphasis mine)
Upvotes: 5