Nelson André
Nelson André

Reputation: 45

System.BadImageFormatException: Could not load file or assembly

I have developed a Windows Service application using Visual Studio 2010 in order to integrate two applications.

In my WinService, I call some API DLL files provided by the destination application developer to create some information in the destination application after getting that information from the origin application.

So my windows service works like some middleware application.

When I run the service I get the following error:

System.BadImageFormatException: Could not load file or assembly 'Interop.ErpBS800, Version=8.5.0.0, Culture=neutral, PublicKeyToken=e076e239d0e78a42' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'Interop.ErpBS800, Version=8.5.0.0, Culture=neutral, PublicKeyToken=e076e239d0e78a42'
   at MaeilKitWintouch.Primavera.CreateDocument(Facturas fac)
   at MaeilKitWintouch.MaeilKitWintouch.ExecuteRequest()


WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

In my Windows 7 x86 laptop everything works great, but in the Windows Small Business Server 2011 Essentials 64-bit I get that error.

I have PLATFORM TARGET = Any CPU and TARGET FRAMEWORK = .NET 4.

Upvotes: 3

Views: 9041

Answers (2)

Martinoxs
Martinoxs

Reputation: 1

My solution for this error was kind different, after 4 days of 'platform war', if I change to x86/x64 I got the same error....

What I did was:

  1. Unload from visual studio all projects and references to the DLL in conflict (also comment all code lines with references), the project must run without errors.
  2. In the main app, go to properties -> compile -> advance compile options -> Tarjet CPU - and in here change to x86
  3. Re compile project
  4. Load project/refrences to DLL
  5. Test if works fine
  6. Uncomment all code lines and recompile

Upvotes: 0

DoomMuffins
DoomMuffins

Reputation: 1204

Your application is likely running in 64-bit mode (which is allowed because you set the Platform Target to Any CPU) and trying to load a 32-bit library.

The blog post Compiling .NET for a Specific Target Platform (Any CPU vs x86 vs x64) summarizes it well.

Upvotes: 4

Related Questions