Windows 7 64 中的 .NET ILMerged DLL 出现 BadImageFormatException
我正在使用 Visual Studio 2008 在 Windows 7 64 位中进行开发。我有一组类库,我使用 ILMerge 将它们合并到单个 DLL 中。然而,当我尝试使用这个合并的 DLL 时,我得到了
[BadImageFormatException:无法加载文件或程序集“MyMergedDll”或其依赖项之一。尝试加载格式不正确的程序。]
我一直在寻找有关此问题的帮助,看起来我需要将 MyMergedDll 中每个项目的 Build 属性设置为目标 x86,所以我这样做了。我还在 Web 服务中设置了所有非 MSTest 项目,在其中引用 MyMergedDll 以定位 x86。但是,我仍然收到此错误。
如果此博客条目值得相信的是,我可以因为这样做而得到这个错误:
public class SpecificClass: BaseClass: where T : class { }
也就是说,对泛型有类约束。不过,该博客条目是 2007 年的,所以我不知道这是否仍然适用。在我跟踪项目中的每个泛型类以检查约束之前,我希望从 StackOverflow 获得一些关于你们认为问题所在的信息。
如果重要的话,MyMergedDll 是强名称签名的。我正在尝试在控制台应用程序和 Web 服务中使用 MyMergedDll。我不知道每次重建 Web 服务时 IIS 是否都会更新,事情是否会变得复杂。对于控制台应用程序,当我在发布模式下构建时,我似乎只会收到 BadImageFormatException
。
I'm developing in Windows 7 64-bit with Visual Studio 2008. I have a collection of class libraries that I merge into a single DLL using ILMerge. When I try to use this merged DLL, however, I get
[BadImageFormatException: Could not load file or assembly 'MyMergedDll' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
I've been searching around for help with this and it looked like I needed to set the Build property in each project in MyMergedDll to target x86, so I did that. I also set all non-MSTest projects in the web service in which I'm referencing MyMergedDll to target x86. I'm still getting this error, however.
If this blog entry is to be believed, I can get this error as a result of doing:
public class SpecificClass: BaseClass: where T : class { }
That is, having a class constraint on a generic. The blog entry is from 2007, though, so I don't know if that still applies. I wanted some input from StackOverflow as to what you guys think the problem is before I go tracking down every generic class in my projects to check constraints.
If it matters, MyMergedDll is strong-name signed. I'm trying to use MyMergedDll in both a console application and in a web service. I don't know if things are perhaps complicated by whether or not IIS is updating every time I rebuild the web service. With the console application, I only seem to get the BadImageFormatException
when I build in Release mode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我让它工作起来,我认为这是通过做两件事来完成的:
BadImageFormatException
。第一件事可能没有必要。我想我只需要 MyMergedDLL 的使用者在发布模式下也以 x86 为目标。我永远无法弄清楚我使用的是哪个版本的 ILMerge,因此我只是使用我在 Microsoft 网站上找到的最新 MSI 重新安装了它。
I got it to work and I think it was from doing two things:
BadImageFormatException
in Release mode.The first thing might not have been necessary. I think I just needed the consumer of MyMergedDLL to also target x86 in Release mode. I never could figure out which version of ILMerge I was using, so I just re-installed it with the latest MSI I could find on Microsoft's site.
您是否仔细检查过您正在使用的 ILMerge 版本?
我问这个问题是因为旧的、不正确的 aspnet_merge 版本(它基本上对 dll 进行相同的合并)导致我们遇到了您所描述的相同问题。我在为其他人回答这个问题时详细介绍了一些细节就这样。
快速查看一下 ILDASM 中的 dll 可能是值得的(当尝试反编译这些坏的 dll 时,Reflector 往往会失败 - 也许并不奇怪),看看您是否可以找出损坏的点以及与代码中对应的内容:它可能会阐明问题。
Have you double-checked the version of ILMerge you are using?
I ask because an old, incorrect version of aspnet_merge (which basically does the same merging of dlls amongst other things) caused us to have the same problems you are describing. I went into some detail when answering this question for someone else on SO.
It may be worth having a quick look at the dll in ILDASM (Reflector tends to fall over when trying to decompile these bad dlls - perhaps unsuprisingly) and see if you can make out the point of corruption and what that corresponds to in your code as it may shed light on the problem.