System.BadImageFormatException:如何修复 .NET 版本不匹配?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/826038/
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
System.BadImageFormatException: How to fix .NET version mismatch?
提问by joshdick
I wrote a dll in VS 2005 that will be loaded by another program that was developed in VS 2003. When that program tries to load my dll, it throws a System.BadImageFormatException: The format of the file 'Foo.dll' is invalid.
我在 VS 2005 中编写了一个 dll,它将被另一个在 VS 2003 中开发的程序加载。当该程序尝试加载我的 dll 时,它会抛出一个 .dll 文件System.BadImageFormatException: The format of the file 'Foo.dll' is invalid。
I searched SO and Google, and it seems that the different version of .NET is the culprit. My question is: How do I fix this?
我搜索了 SO 和 Google,似乎不同版本的 .NET 是罪魁祸首。我的问题是:我该如何解决这个问题?
(I cannot modify the program developed in VS 2003.)
(我无法修改在 VS 2003 中开发的程序。)
采纳答案by Markus Nigbur
Compile the VS2005 Project with the same .Net Version as your VS2003 Project uses. Or, depending of the size of your VS2003 Project, reflector and rewrite it. That's common practice for projects over here, where for some obscure reason there is no more VSS version available.
使用与 VS2003 项目使用的相同的 .Net 版本编译 VS2005 项目。或者,根据您的 VS2003 项目的大小,反射器并重写它。这是这里的项目的常见做法,由于某些晦涩的原因,没有更多可用的 VSS 版本。
回答by John Downey
I got this error when I was running the 64bit version of the CLR and trying to load an assembly that was marked 32bit only. The specific assembly in my case was the Oracle.DataAccess.dll that comes as part of ODP.NET.
当我运行 64 位版本的 CLR 并尝试加载仅标记为 32 位的程序集时,出现此错误。在我的案例中,特定程序集是作为 ODP.NET 一部分的 Oracle.DataAccess.dll。
回答by bluwater2001
SOLUTION: If you are on IIS7, Right Click/ Advanced Settings on the Specific Application Pool of the website and select True on Enable 32-Bit Applications. It should work.
解决方案:如果您使用的是 IIS7,请在网站的特定应用程序池上右键单击/高级设置,然后在启用 32 位应用程序上选择 True。它应该工作。

