C# .net 框架错误 (HRESULT 0x8007000B)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18007967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.net Framework Error (HRESULT 0x8007000B)
提问by Adam Jakiela
I have a C# application which was written on a 32bit windows XP machine with Visual Studio 2005. The application runs fine on Windows XP machines, however when I try to run it on a 64bit Windows 7 professional machine, I get the following dialog-box on start up:
我有一个 C# 应用程序,它是在带有 Visual Studio 2005 的 32 位 Windows XP 机器上编写的。该应用程序在 Windows XP 机器上运行良好,但是当我尝试在 64 位 Windows 7 专业机器上运行它时,我得到以下对话框启动时:
Here is the full text from the details.
这是详细信息的全文。
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.
Has anyone else encountered this error and succeeded in solving it?
有没有其他人遇到过这个错误并成功解决了它?
采纳答案by Wes Haggard
While your main app might be built for AnyCPU are you sure all the assemblies are AnyCPU? Do you have any native assemblies or assemblies that contain native code? Are they built against x86?
虽然您的主应用程序可能是为 AnyCPU 构建的,但您确定所有程序集都是 AnyCPU 吗?您是否有任何本机程序集或包含本机代码的程序集?它们是针对 x86 构建的吗?
file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
This tells me that the app is running as an x64 process but it would appear that there is some assembly that isn't AnyCPU or x64 which is likely the cause of the BadImageFormatException.
这告诉我该应用程序正在作为 x64 进程运行,但似乎有一些程序集不是 AnyCPU 或 x64,这可能是 BadImageFormatException 的原因。
One thing you can try is to run the application from a 32-bit command prompt (c:\windows\SysWow64\cmd.exe) to force it to be a 32-bit process and see if that works. If that works then there is definitely some assembly that is not AnyCPU.
您可以尝试的一件事是从 32 位命令提示符 (c:\windows\SysWow64\cmd.exe) 运行该应用程序,以强制其成为 32 位进程并查看是否有效。如果可行,那么肯定有一些不是 AnyCPU 的程序集。
回答by Leonel Sarmiento
From my experience the cause of that error is the .Net Framework Version
根据我的经验,该错误的原因是 .Net Framework 版本
Check your .Net Framework version and update and also check the .Net version of your application.
检查您的 .Net Framework 版本和更新,并检查您的应用程序的 .Net 版本。
回答by Yuliia Ashomok
Project Properties -> Build -> Platform target -> x86may solve this problem.
Project Properties -> Build -> Platform target -> x86可以解决这个问题。
回答by Ashish
My issue was solved by compiling with 32 bit as Wix currently doesnt have 64. Your installer msi will in any case be 64 bit
我的问题是通过用 32 位编译解决的,因为 Wix 目前没有 64。无论如何,您的安装程序 msi 将是 64 位
回答by JinSnow
In my case I had the 0x8007000B error because the app was running in 32 bit, on my 64 windows 7. I solved it by going in windows/syswov64 folder changing the MSVCR110.dll version 64 bit with the MSVCR110.dll version 32 bit.
就我而言,我遇到了 0x8007000B 错误,因为该应用程序在 64 位 Windows 7 上以 32 位运行。我通过进入 windows/syswov64 文件夹将 MSVCR110.dll 版本 64 位更改为 MSVCR110.dll 版本 32 位来解决此问题。
(Just don't forget to put back the 64 dll after. Each time you need to run your 32 bit app, just move the dll 32 on it).
(只是不要忘记在之后放回 64 dll。每次您需要运行 32 位应用程序时,只需将 dll 32 移到它上面即可)。
You could find the dll versions here(Unzip it before pasting into the syswov64 folder).
您可以在此处找到 dll 版本(在粘贴到 syswov64 文件夹之前将其解压缩)。
回答by Rao
I would like to add also my finding: I unchecked in a project properties in Build tab a "Prefer 32-bit" and got this error. After re-checking, it was gone. I have Any CPU set as a target.
我还想添加我的发现:我在“构建”选项卡中的项目属性中取消选中“首选 32 位”并收到此错误。重新检查后,它消失了。我将任何 CPU 设置为目标。
I am aware that this is not a definite solution, just a symptom-solving, but it might be of help.
我知道这不是一个明确的解决方案,只是解决症状,但它可能会有所帮助。
回答by smoore4
The fix for me was to change the Application Pool in IIS. Open the application pool properties and go to Advanced Settings... Then change "Enable 32-bit Applications" to True. The default is False for a new one. The code part was set to "Any CPU" although I have fixed issues in the past by setting the CPU to x86.
我的解决方法是更改 IIS 中的应用程序池。打开应用程序池属性并转到高级设置...然后将“启用 32 位应用程序”更改为 True。新的默认值为 False。尽管我过去通过将 CPU 设置为 x86 解决了问题,但代码部分设置为“任何 CPU”。
回答by MD. Nazmul Kibria
One of the most common mistake is we forgot to change the test program and wrapper program to the correct platform. See the below image
最常见的错误之一是我们忘记将测试程序和包装程序更改为正确的平台。见下图
(in the top bar it is showing the platform is x64 but you need to make sure if it is really exists in the 2nd image ...)
(在顶部栏中,它显示平台是 x64,但您需要确定它是否真的存在于第二张图片中...)
Make sure you have right configuration on the Configuration Manager...if your config do not match with the actual config of your c++ dll it will give BadImageFormatException.
确保您在配置管理器上有正确的配置...如果您的配置与您的 c++ dll 的实际配置不匹配,它将给出 BadImageFormatException。
I learned from the mistake after searching a lot ... and finally got this
经过大量搜索,我从错误中吸取了教训......终于得到了这个
回答by Peter Chambers
I had this error when my solution called a 32 bit dll. In addition to making the platform changes referred to in other replies above, in VS2017 Project {yourproject} Properties Services, I had to change "Use Windows authentication" to "Use Forms authentication"
当我的解决方案调用 32 位 dll 时,我遇到了这个错误。除了进行上面其他回复中提到的平台更改之外,在VS2017项目{yourproject}属性服务中,我不得不将“使用Windows身份验证”更改为“使用表单身份验证”
回答by Talha Imam
I had to combine solutions from 2-3 different answers to resolve the same error. The reason is, the final setup had dlls from both x86 and x64 platforms(in separate folders for separate exes).
我不得不结合 2-3 个不同答案的解决方案来解决相同的错误。原因是,最终设置有来自 x86 和 x64 平台的 dll(在单独的文件夹中用于单独的 exe)。
1) I set the platform target of my main app as 64 bit and left configuration settings as it is and built it:
1) 我将主应用程序的平台目标设置为 64 位,并保留配置设置并构建它:
2) I set the Target platform of my Deployment project as x64.
2)我将部署项目的目标平台设置为 x64。
3) The dlls were getting mixed between the folders so i checked source path of all dlls in the File Types Editor one by one and replaced them according to their architectures.
3)dll在文件夹之间混合,所以我在文件类型编辑器中一一检查了所有dll的源路径,并根据它们的体系结构替换它们。
4) Finally built the deployment project with following configuration settings:
The above mentioned combination is the only one that worked.
上述组合是唯一有效的组合。