System.BadImageFormatException:如何修复.NET版本不匹配?不匹配、版本、System、BadImageFormatException

2023-09-03 12:32:37 作者:心野路子正

我写了VS 2005中一个dll将由那是在2003年VS当该程序试图加载我的DLL开发的另一个程序加载,它抛出一个 System.BadImageFormatException:的格式文件'Foo.dll无效

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.

我搜查SO和谷歌,以及似乎不同版本的.NET是罪魁祸首。我的问题是:我该如何解决这个问题

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?

(我不能修改VS 2003开发的程序。)

(I cannot modify the program developed in VS 2003.)

推荐答案

编译VS2005项目使用相同的.NET版本为您的VS2003项目使用。 或者,这取决于你的VS2003项目,反射体的大小和重写。这对在这里的项目普遍的做法,在一些模糊的原因是没有更多的VSS版本。

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.