Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.BadImageFormatException: Could not load file or assembly

Tags:

windows

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.

like image 221
Nelson André Avatar asked Dec 06 '25 01:12

Nelson André


1 Answers

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.

like image 191
DoomMuffins Avatar answered Dec 08 '25 15:12

DoomMuffins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!