.NET Framework 错误 (HRESULT 0x8007000B)

25
我有一个使用Visual Studio 2005在32位Windows XP机器上编写的C#应用程序。该应用程序可以在Windows XP机器上正常运行,但是当我尝试在64位Windows 7专业版机器上运行它时,启动时会弹出以下对话框:

enter image description here

这是来自详细信息的完整文本。
  See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
   at ICSNeoCSharp.IcsNeoDll.icsneoTxMessages(Int32 hObject, IcsSpyMessage& pMsg, Int32 lNetworkID, Int32 lNumMessages)
   at ICSNeoCSharp.FormDTCApplication.transmitFlowControl(Int32 myArbID) in C:\Documents and Settings\Administrator\Desktop\Adam Stuff ThinkPad\DTC Checker FINAL\frmDTCApp.cs:line 1750
   at ICSNeoCSharp.FormDTCApplication.flowControlTimer_Tick(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\Desktop\Adam Stuff ThinkPad\DTC Checker FINAL\frmDTCApp.cs:line 5166
   at System.Windows.Forms.Timer.OnTick(EventArgs e)
   at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5472 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
----------------------------------------
DTC Checker V1.0
    Assembly Version: 1.0.4960.25549
    Win32 Version: 1.0.4960.25549
    CodeBase: file:///C:/DTC%20Checker%20V1.0%20R3/DTC%20Checker%20V1.0%20R3.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5468 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5467 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5467 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Microsoft.Office.Interop.Excel
    Assembly Version: 12.0.0.0
    Win32 Version: 12.0.6600.1000
    CodeBase: file:///C:/Windows/assembly/GAC/Microsoft.Office.Interop.Excel/12.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.Excel.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

还有其他人遇到过这个错误并成功解决了吗?


你是在x64上运行exe还是解决方案? - Arshad
我在 Windows 7 机器上没有 Visual Studio。 - Adam Jakiela
你已经为x64计算机创建了你的exe文件吗? - Arshad
1
我正在构建任何CPU。 - Adam Jakiela
我尝试了专门为64位构建,但没有成功。 - Adam Jakiela
重新编译代码:项目属性 -> 编译 -> 高级编译选项按钮 => 然后您可以在组合框中选择目标 CPU。 - Arshad
10个回答

32

你的主应用程序可能是为AnyCPU构建的,但是你确定所有的程序集都是AnyCPU吗?你有任何包含本机代码的本机程序集或程序集吗?它们是否针对x86构建?

file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll

这告诉我应用正在作为x64进程运行,但似乎存在某些程序集不是AnyCPU或x64,这很可能是BadImageFormatException的原因。

你可以尝试从32位命令提示符(c:\windows\SysWow64\cmd.exe)中运行应用程序,强制其成为32位进程,看看是否能够正常工作。如果可以,则肯定存在一些不是AnyCPU的程序集。


我尝试在命令提示符中运行它,但这并没有起作用。我认为你说的64位汇编代码可能有问题。有没有办法在64位系统上运行32位汇编文件? - Adam Jakiela

9

项目属性 -> 构建 -> 平台目标 -> x86 可能会解决这个问题。


4

最常见的错误之一是我们忘记将测试程序和包装程序更改为正确的平台。请参见以下图像。

enter image description here

在顶部栏中显示平台为x64,但您需要确保它是否真的存在于第二张图像中...

enter image description here

确保您在配置管理器上拥有正确的配置...如果您的配置与C++ dll的实际配置不匹配,它将会产生BadImageFormatException。

在搜索了很多后,我从错误中学到了教训...最终得到了这个解决方案


3
在我的情况下,我遇到了0x8007000B错误,因为该应用程序在64位Windows 7上运行的32位模式。我通过进入windows/syswov64文件夹并将MSVCR110.dll版本64位更改为MSVCR110.dll版本32位来解决此问题。 (只是不要忘记在之后放回64位dll。每次需要运行32位应用程序时,只需将dll 32移动到它上面即可)。您可以在这里找到dll版本(在将其粘贴到syswov64文件夹之前,请先解压缩它)。

1
我的解决方法是更改IIS中的应用程序池。打开应用程序池属性,进入高级设置...然后将“启用32位应用程序”更改为True。对于新的应用程序池,默认值为False。代码部分设置为“任何CPU”,尽管我过去曾通过将CPU设置为x86来解决问题。

1

我不得不结合2-3个不同答案的解决方案来解决相同的错误。原因是,最终设置包含了来自x86和x64平台的dll(分别放在不同的文件夹中)。

1)我将主应用程序的平台目标设置为64位,并保留配置设置并构建它: enter image description here

2)我将部署项目的目标平台设置为x64。

3)由于dlls混合在文件夹中,所以我逐个检查了文件类型编辑器中所有dlls的源路径,并根据其体系结构进行了替换。

4)最后使用以下配置设置构建了部署项目: enter image description here

上述组合是唯一有效的。


1
根据我的经验,该错误的原因是 .Net Framework 版本。请检查您的 .Net Framework 版本并进行更新,还要检查您的应用程序的 .Net 版本。

0

0
我想补充我的发现:在项目属性的“生成”选项卡中取消选中“首选 32 位”,就会出现这个错误。重新选中后,错误消失了。我的目标是任意 CPU。
我知道这不是一个确定的解决方案,只是一种症状解决方法,但它可能会有所帮助。

0

当我的解决方案调用32位dll时,我遇到了这个错误。除了进行其他回复中提到的平台更改之外,在VS2017项目{yourproject}属性服务中,我还需要将“使用Windows身份验证”更改为“使用表单身份验证”。

Services tab is selected, and in the Authentication section "Use Forms authentication" is selected and circled in red


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接