System.BadImageFormatException:无法加载文件或程序集

问题描述:

我开发了一个使用Visual Studio 2010的Windows服务应用程序,以便集成两个应用程序。System.BadImageFormatException:无法加载文件或程序集

在我的WinService中,我调用目标应用程序开发人员提供的一些API DLL文件,以便在从原始应用程序获取该信息后在目标应用程序中创建一些信息。

所以我的Windows服务就像一些中间件应用程序。

当我跑我得到以下错误的服务:

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]. 

在我的Windows 7笔记本电脑的x86一切都很正常,但在Windows小企业服务器2011年精要64位我得到这个错误。

我有PLATFORM TARGET =任何CPU和目标框架= .NET 4

+1

更改目标平台的x86 – asawyer

您的应用程序在64位模式下运行的可能性(这是允许的,因为你的目标平台设置为任何CPU)和试图加载一个32位的库。

博客文章Compiling .NET for a Specific Target Platform (Any CPU vs x86 vs x64)总结得很好。

+0

的问题是我有它在x86和我有同样的错误。有人告诉我将其更改为任何CPU,但仍然是相同的错误。 –

我对这个错误的解决方案是一种不同的,后“平台战争”的4天,如果我改变在x86/x64,我得到了同样的错误....

我所做的是:

  1. 从Visual Studio中卸载所有项目和对冲突的DLL的引用(也可以使用引用注释所有代码行),项目必须无错地运行。
  2. 在主应用程序,进入属性 - >编译 - >提前编译选项 - > Tarjet CPU - 在这里更改为86
  3. 重新编制项目
  4. 负载项目/ refrences对DLL
  5. 测试是否工作正常
  6. 取消注释的所有代码行,并重新编译