I'm calling functions from a 32-bit unmanaged DLL on a 64-bit system. What I get is:
我在64位系统上调用来自32位非托管DLL的函数。我得到的是:
BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
BadImageFormatException:尝试用不正确的格式加载程序。(从HRESULT例外:0 x8007000b)
At first, I had my projects set to the Any CPU platform, so I changed them both to x86, but this error is still occurring. That's really the only fix I know for this.
起初,我将我的项目设置为任何一个CPU平台,所以我将它们都更改为x86,但是这个错误仍然在发生。这是我知道的唯一补救办法。
The DLLs aren't corrupt or anything, because I can use them with other programs (that I don't have the source to). I thought that perhaps it wasn't finding a dependency, but I checked and they're all there. Plus, wouldn't it throw a DllNotFoundException
in that case?
dll没有损坏或任何东西,因为我可以使用它们与其他程序(我没有源代码)。我想也许它没有找到一个依赖,但我检查了,它们都在那里。另外,在这种情况下,它不会抛出一个DllNotFoundException吗?
What else can I do? And before you say "Use a 64-bit unmanaged DLL instead," let me point out that there isn't one. ;)
我还能做什么?在您说“使用64位非托管DLL”之前,请允许我指出,这里没有。,)
15 个解决方案
#1
474
If you try to run 32-bit applications on IIS 7 (and/or 64-bit OS machine), you will get the same error. So, from the IIS 7, right click on the applications' application pool and go to "advanced settings" and change "Enable 32-Bit Applications" to "TRUE".
如果您试图在IIS 7(和/或64位OS机器)上运行32位应用程序,您将会得到相同的错误。因此,从iis7中,右键单击应用程序的应用程序池,然后切换到“高级设置”,并将“启用32位应用程序”改为“TRUE”。
Restart your website and it should work.
重新启动你的网站,它应该会起作用。
#2
112
Somehow, the Build checkbox in the Configuration Manager had been unchecked for my executable, so it was still running with the old Any CPU build. After I fixed that, Visual Studio complained that it couldn't debug the assembly, but that was fixed with a restart.
不知何故,配置管理器中的Build复选框对于我的可执行文件是未选中的,因此它仍然与旧的任何CPU构建一起运行。在我修复之后,Visual Studio抱怨它不能调试程序集,但是它是通过重新启动修复的。
#3
54
In Visual Studio, Right Click your project -> On the left pane click the Build tab,
在Visual Studio中,右键单击你的project ->在左边的面板上单击Build选项卡,
under Platform Target select x86 (or more generally the architecture to match with the library you are linking to)
在平台目标下选择x86(或更一般的架构,以与您所链接的库相匹配)
I hope this helps someone! :)
我希望这能帮助别人!:)
#4
45
I just had this problem also. Tried all the suggestions here, but they didn't help.
我也有这个问题。我试了所有的建议,但都无济于事。
I found another thing to check that fixed it for me. In Visual Studio, right-click on the project and open "Properties". Click on the "Compile" tab and then click on "Advanced Compile Options" at the bottom.
我找了另外一件东西来帮我修理。在Visual Studio中,右键单击项目并打开“属性”。点击“编译”选项卡,然后点击底部的“高级编译选项”。
Check the dropdown "Target CPU". It should match the "Platform" you are building. That is, if you are building "Any CPU" then "Target CPU" should say "Any CPU". Go through all of your Platforms by making them active and check this setting.
检查下拉“目标CPU”。它应该匹配您正在构建“平台”。也就是说,如果您正在构建“任何CPU”然后“目标CPU”应该说“任何CPU”。去通过你所有的平台,使他们积极和检查这个设置。
#5
#6
19
If you encounter this error when you click green arrow button to run the application, but still want to run the app in 64 bit. You can do this in VS 2013 or 2015
如果您在单击绿色箭头按钮运行应用程序时遇到此错误,但仍然希望在64位运行该应用程序。你可以在VS 2013或2015年完成。
Go to: Tools > Options > Projects and Solutions > Web Projects > Use the 64 bit version of IIS Express
至:工具>选项>项目和解决方案> Web项目>使用IIS Express的64位版本
#7
8
A bit off topic for this post, but searching for this error message brought me here.
这篇文章有点偏离主题,但是搜索这个错误消息把我带到了这里。
If you are building through team system and getting this error, the build definition process tab has a "MSBuild Platform" setting. If this is set to "Auto", you may experience this problem. Changing it to "X86" can also resolve the error.
如果您正在构建通过团队系统,此错误,构建过程定义选项卡中有一个“MSBuild平台”设置。如果这是设置为“自动”时,您可能会遇到这个问题。改变它“X86”也可以解决错误。
#8
7
In my case I was using a native DLL in C#. This DLL depended on couple of other DLLs that were missing. Once those other DLLs were added everything worked.
在我的例子中,我使用的是c#中的本地DLL。这个DLL依赖于其他丢失的DLL。一旦其他的dll被添加进来,一切都工作了。
#9
3
Also see this answer, which solved the same problem for me.
也看到这个答案,也解决了同样的问题。
Posted by Luis Mack on 5/12/2010 at 8:50 AM I've found the same problem, only for a specific project when compiling on a 64-bit machine. A fix that SEEMS to work is to manually alter one character in the image stream EVERY TIME the usercontrol or form is edited in the designer
Luis Mack在2010年5月12日早上8点50分发表的文章中,我发现了同样的问题,只在一个特定的项目中编译在64位机器上。在设计器中,每次用户控件或窗体被编辑时,似乎都需要手工修改图像流中的一个字符。
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
Change to
改变
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
That is 00LjAuMC4w back to 0yLjAuMC4w at the end of the line (00 back to 0y)
这是00LjAuMC4w回到0yLjAuMC4w在线的末端(00回到0y)
#10
2
In my case, I am using a tiny .exe that reloads the referenced DLLs via Reflection. So I just do these steps which saves my day:
在我的例子中,我使用的是一个很小的.exe,它通过反射重新加载引用的dll。所以我只是做这些步骤来节省我的时间:
From project properties on solution explorer, at build tab, I choose target platfrom x86
从解决方案资源管理器的项目属性,到build选项卡,我从x86选择目标平台。
#11
2
In my case, I was running tests through MSTest and found out that I was deploying both a 32-bit and 64-bit DLL to the test directory. The program was favoring the 64-bit DLL and causing it to fail.
在我的例子中,我通过MSTest运行测试,发现我正在将32位和64位的DLL部署到测试目录中。该程序支持64位的DLL并导致它失败。
TL;DR Make sure you only deploy 32-bit DLLs to tests.
请确保您只将32位dll部署到测试中。
#12
1
I got this issue solved in the 'Windows' way. After checking all my settings, cleaning the solution and rebuilding it, I simply close the solution and reopened it. Then it worked, so VS probably didn't get rid of some stuff during cleaning. When logical solutions don't work, I usually turn to illogical (or seemingly illogical) ones. Windows doesn't let me down. :)
我用Windows的方式解决了这个问题。检查完所有的设置后,清理解决方案并重新构建它,我只需关闭解决方案并重新打开它。然后,它起作用了,所以VS可能在清洗过程中没有处理掉一些东西。当逻辑解决方案不起作用时,我通常会求助于不合逻辑(或看起来不合逻辑)的解决方案。Windows不会让我失望。:)
#13
1
I was able to fix this issue by matching my build version to the .NET version on the server.
通过将构建版本与服务器上的. net版本相匹配,我能够解决这个问题。
I double clicked the .exe just to see what would happen and it told me to install 4.5....
我双点击. exe,看看会发生什么,它告诉我安装4.5 ....
So I downgraded to 4.0 and it worked!
所以我降级到4.0,它成功了!
So make sure your versions match. It ran on my dev box fine, but server had older .NET version.
所以要确保你的版本匹配。它运行在我的dev box上,但是服务器有更老的。net版本。
#14
0
In my case it was wrong content of the file. DLL was downloaded from the web, but content of the DLL was HTML page :D Try to check if it is binary file, if it seems like correct DLL :)
在我的情况下,文件的内容是错误的。DLL是从web上下载的,但是DLL的内容是HTML页面:D试着检查它是否是二进制文件,如果它看起来像正确的DLL:)
#15
0
Building on the answer of @paibamboo
基于@ pai竹子的答案。
He said: Go to: Tools > Options > Projects and Solutions > Web Projects > Use the 64 bit version of IIS Express
他说:Go to:工具>选项>项目和解决方案>网络项目>使用IIS Express的64位版本。
My coworker had this box checked (he explicitly looked for it), but had the error message in question. After some hours he unchecked the box and checked it again. Lo and behold: The code now ran with success.
我的同事检查了这个复选框(他明确地查找了它),但是有一个错误消息。过了几个小时,他检查了箱子,又检查了一遍。瞧,现在代码运行成功了。
It seems, that there are two places where the state of this box ist saved which became out of sync. Un- and rechecking it synced it again.
似乎有两个地方,这个箱子的保存状态是不同步的。然后重新检查它。
Question for more knowledgable users: Was there an update or something last week (for VS 2015) which de-synced the states?
对更多有知识的用户的问题:是否有更新或上周(针对VS 2015)的更新?
#1
474
If you try to run 32-bit applications on IIS 7 (and/or 64-bit OS machine), you will get the same error. So, from the IIS 7, right click on the applications' application pool and go to "advanced settings" and change "Enable 32-Bit Applications" to "TRUE".
如果您试图在IIS 7(和/或64位OS机器)上运行32位应用程序,您将会得到相同的错误。因此,从iis7中,右键单击应用程序的应用程序池,然后切换到“高级设置”,并将“启用32位应用程序”改为“TRUE”。
Restart your website and it should work.
重新启动你的网站,它应该会起作用。
#2
112
Somehow, the Build checkbox in the Configuration Manager had been unchecked for my executable, so it was still running with the old Any CPU build. After I fixed that, Visual Studio complained that it couldn't debug the assembly, but that was fixed with a restart.
不知何故,配置管理器中的Build复选框对于我的可执行文件是未选中的,因此它仍然与旧的任何CPU构建一起运行。在我修复之后,Visual Studio抱怨它不能调试程序集,但是它是通过重新启动修复的。
#3
54
In Visual Studio, Right Click your project -> On the left pane click the Build tab,
在Visual Studio中,右键单击你的project ->在左边的面板上单击Build选项卡,
under Platform Target select x86 (or more generally the architecture to match with the library you are linking to)
在平台目标下选择x86(或更一般的架构,以与您所链接的库相匹配)
I hope this helps someone! :)
我希望这能帮助别人!:)
#4
45
I just had this problem also. Tried all the suggestions here, but they didn't help.
我也有这个问题。我试了所有的建议,但都无济于事。
I found another thing to check that fixed it for me. In Visual Studio, right-click on the project and open "Properties". Click on the "Compile" tab and then click on "Advanced Compile Options" at the bottom.
我找了另外一件东西来帮我修理。在Visual Studio中,右键单击项目并打开“属性”。点击“编译”选项卡,然后点击底部的“高级编译选项”。
Check the dropdown "Target CPU". It should match the "Platform" you are building. That is, if you are building "Any CPU" then "Target CPU" should say "Any CPU". Go through all of your Platforms by making them active and check this setting.
检查下拉“目标CPU”。它应该匹配您正在构建“平台”。也就是说,如果您正在构建“任何CPU”然后“目标CPU”应该说“任何CPU”。去通过你所有的平台,使他们积极和检查这个设置。
#5
22
If you are using Any CPU, you might encounter this issue if the Prefer 32-bit option is checked:
如果您正在使用任何CPU,您可能会遇到这样的问题:如果选择的是32位选项,则会检查:
Make sure you uncheck this option in the project's property's Build tab!
确保在项目的“构建”选项卡中取消选中此选项!
#6
19
If you encounter this error when you click green arrow button to run the application, but still want to run the app in 64 bit. You can do this in VS 2013 or 2015
如果您在单击绿色箭头按钮运行应用程序时遇到此错误,但仍然希望在64位运行该应用程序。你可以在VS 2013或2015年完成。
Go to: Tools > Options > Projects and Solutions > Web Projects > Use the 64 bit version of IIS Express
至:工具>选项>项目和解决方案> Web项目>使用IIS Express的64位版本
#7
8
A bit off topic for this post, but searching for this error message brought me here.
这篇文章有点偏离主题,但是搜索这个错误消息把我带到了这里。
If you are building through team system and getting this error, the build definition process tab has a "MSBuild Platform" setting. If this is set to "Auto", you may experience this problem. Changing it to "X86" can also resolve the error.
如果您正在构建通过团队系统,此错误,构建过程定义选项卡中有一个“MSBuild平台”设置。如果这是设置为“自动”时,您可能会遇到这个问题。改变它“X86”也可以解决错误。
#8
7
In my case I was using a native DLL in C#. This DLL depended on couple of other DLLs that were missing. Once those other DLLs were added everything worked.
在我的例子中,我使用的是c#中的本地DLL。这个DLL依赖于其他丢失的DLL。一旦其他的dll被添加进来,一切都工作了。
#9
3
Also see this answer, which solved the same problem for me.
也看到这个答案,也解决了同样的问题。
Posted by Luis Mack on 5/12/2010 at 8:50 AM I've found the same problem, only for a specific project when compiling on a 64-bit machine. A fix that SEEMS to work is to manually alter one character in the image stream EVERY TIME the usercontrol or form is edited in the designer
Luis Mack在2010年5月12日早上8点50分发表的文章中,我发现了同样的问题,只在一个特定的项目中编译在64位机器上。在设计器中,每次用户控件或窗体被编辑时,似乎都需要手工修改图像流中的一个字符。
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
Change to
改变
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
That is 00LjAuMC4w back to 0yLjAuMC4w at the end of the line (00 back to 0y)
这是00LjAuMC4w回到0yLjAuMC4w在线的末端(00回到0y)
#10
2
In my case, I am using a tiny .exe that reloads the referenced DLLs via Reflection. So I just do these steps which saves my day:
在我的例子中,我使用的是一个很小的.exe,它通过反射重新加载引用的dll。所以我只是做这些步骤来节省我的时间:
From project properties on solution explorer, at build tab, I choose target platfrom x86
从解决方案资源管理器的项目属性,到build选项卡,我从x86选择目标平台。
#11
2
In my case, I was running tests through MSTest and found out that I was deploying both a 32-bit and 64-bit DLL to the test directory. The program was favoring the 64-bit DLL and causing it to fail.
在我的例子中,我通过MSTest运行测试,发现我正在将32位和64位的DLL部署到测试目录中。该程序支持64位的DLL并导致它失败。
TL;DR Make sure you only deploy 32-bit DLLs to tests.
请确保您只将32位dll部署到测试中。
#12
1
I got this issue solved in the 'Windows' way. After checking all my settings, cleaning the solution and rebuilding it, I simply close the solution and reopened it. Then it worked, so VS probably didn't get rid of some stuff during cleaning. When logical solutions don't work, I usually turn to illogical (or seemingly illogical) ones. Windows doesn't let me down. :)
我用Windows的方式解决了这个问题。检查完所有的设置后,清理解决方案并重新构建它,我只需关闭解决方案并重新打开它。然后,它起作用了,所以VS可能在清洗过程中没有处理掉一些东西。当逻辑解决方案不起作用时,我通常会求助于不合逻辑(或看起来不合逻辑)的解决方案。Windows不会让我失望。:)
#13
1
I was able to fix this issue by matching my build version to the .NET version on the server.
通过将构建版本与服务器上的. net版本相匹配,我能够解决这个问题。
I double clicked the .exe just to see what would happen and it told me to install 4.5....
我双点击. exe,看看会发生什么,它告诉我安装4.5 ....
So I downgraded to 4.0 and it worked!
所以我降级到4.0,它成功了!
So make sure your versions match. It ran on my dev box fine, but server had older .NET version.
所以要确保你的版本匹配。它运行在我的dev box上,但是服务器有更老的。net版本。
#14
0
In my case it was wrong content of the file. DLL was downloaded from the web, but content of the DLL was HTML page :D Try to check if it is binary file, if it seems like correct DLL :)
在我的情况下,文件的内容是错误的。DLL是从web上下载的,但是DLL的内容是HTML页面:D试着检查它是否是二进制文件,如果它看起来像正确的DLL:)
#15
0
Building on the answer of @paibamboo
基于@ pai竹子的答案。
He said: Go to: Tools > Options > Projects and Solutions > Web Projects > Use the 64 bit version of IIS Express
他说:Go to:工具>选项>项目和解决方案>网络项目>使用IIS Express的64位版本。
My coworker had this box checked (he explicitly looked for it), but had the error message in question. After some hours he unchecked the box and checked it again. Lo and behold: The code now ran with success.
我的同事检查了这个复选框(他明确地查找了它),但是有一个错误消息。过了几个小时,他检查了箱子,又检查了一遍。瞧,现在代码运行成功了。
It seems, that there are two places where the state of this box ist saved which became out of sync. Un- and rechecking it synced it again.
似乎有两个地方,这个箱子的保存状态是不同步的。然后重新检查它。
Question for more knowledgable users: Was there an update or something last week (for VS 2015) which de-synced the states?
对更多有知识的用户的问题:是否有更新或上周(针对VS 2015)的更新?