为什么我可能会没有发现异常在Vista上,但不是XP中的DLL?可能会、异常、发现、不是

2023-09-04 03:09:05 作者:余生与你无关

我有一个应用程序依赖于几个托管库。反过来这些托管库依靠一些非托管库。

I have an app that relies on several managed libraries. These managed libraries in turn rely on some unmanaged libraries.

当我部署应用程序的机器运行XP,它运行良好。当我做同样的一台运行Vista系统,我得到一个DLL未发现异常。

When I deploy the app to a machine running XP, it runs fine. When I do the same on a machine running Vista, I get a DLL not found exception.

我都试过一个VS2010安装项目和NSIS安装做了部署和它在这两种情况下是相同的。

I've tried both a VS2010 setup project and an NSIS installer to do the deployment and it's the same in both cases.

为什么会出现这种情况?我能做些什么来解决它?

Why might this happen? What can I do to get around it?

更新 - 更多细节

在这两个安装程序检查的.NET 4.0的安装,并安装它,如果需要的话 在Vista的电脑是64位,但安装被定向到86 Program Files文件夹如预期 在这两种情况下我有一个管理员帐户 的DLL文件都保存在同一目录中的可执行文件 据我所知,这些文件得到复制到正确的目录

更新2

完整的错误是在 http://pastebin.ca/2046487 在该DLL是Audiere.Net.dll,这是我的一个,是一个托管库。

我不知道是否该错误意味着它无法找到Audiere.Net.dll,还是无法加载它,因为它的一个依赖关系不能被发现。

I'm not sure if that error means that it can't find Audiere.Net.dll, or whether it can't load it because one of it's dependencies can't be found.

更新3 - 从进程监视器东西

Update 3 - Stuff from Process Monitor

运行的进程监视器(感谢迈赫达德!)还有不具有成功的状态几个条目之后。其中有些是找不到名称,有些是未找到路径。 (它甚至查询PDB文件,我原本以为只用于调试)。这真的很难,看看哪些条目可能是一条通往实际的故障。无论如何,我已经的情况下上传日志(过滤,有一个相关的路径),这意味着什么给任何人。

After running process monitor (thanks Mehrdad!) there are several entries which don't have a status of "SUCCESS". Some of these are "NAME NOT FOUND" and some are "PATH NOT FOUND". (It's even querying the PDB files, which I had thought were only used by a debugger.) It's really hard to see which entries might be the one leading to the actual failure. Anyway, I've uploaded the log (filtered to have a relevant path) in case it means something to anyone.

更新4 - 新增.pdb文件

Update 4 - Added .pdb files

所以,我有点绝望了,并包含在.pdb文件来安装程序的输出。我认为这将是无用的,但它实际上导致了更多有用的错误。而不是简单地说DLL没有找到,我现在得到一个BadImageFormatException。谷歌搜索这告诉我,这是编译在x86,但正在运行在x64二进制文件的共同问题(如Vista的机器)。

So I kinda got desperate and included the .pdb files to the output of the installer. I thought it would be useless, but it actually resulted in a more useful error. Rather than simply saying DLL not found, I now get a BadImageFormatException. Googling this tells me that this is a common problem for binaries compiled on x86 but being run on x64 (as the Vista machine is).

建议的补救措施是迫使它针对x86的,但Audiere.Net.dll已是。莫非故障谎言和它所包装的库?

The suggested remedy is to force it to target x86, but Audiere.Net.dll already was. Could the fault lie with the library that it wraps?

推荐答案

该解决方案被证明是相当简单:需要非托管的dll的一个重新编译为64

The solution turned out to be quite straightforward: one of the unmanaged DLLs needed to be recompiled for x64.

关键步骤:

在检查过程监视器的错误可能的来源。仔细看一下错误报告的Windows提供了应用程序崩溃时发送。 包括托管库的.pdb文件。这似乎导致更多的错误消息。 在这些错误信息不仅指定其托管库造成此错误,同时也表示,这是一个在x86 / x64的问题。 ( BadImageFormatException ) 在以下一些合理的建议,检查的的非托管库的所有的瞄准86。 (雷人,但它的好是肯定的。) 重新编译的麻烦托管库的非托管的依赖在x64机器上。 在编写一个安装脚本复制适当的(x86或x64)版本的DLL。 利润! Check process monitor for likely sources of error. Look carefully at the error report that Windows offers to send when the app crashes. Include the .pdb files for managed libraries. This seemed to result in more informative error messages. These error messages not only specified which managed library was causing the error, but also indicated that it was a x86/x64 issue. (BadImageFormatException) Following some sound advice, check that all of the unmanaged libraries are targeting x86. (Mine were, but it's good to be sure.) Recompile the unmanaged dependencies of the troublesome managed library on an x64 machine. Write an install script that copies the appropriate (x86 or x64) version of the DLL. Profit!

具体细节:

在我看来是与 Audiere.Net.dll 的问题,但实际上是由与 libaudieresharpglue.dll 。 在我使用NSIS的安装程序。为了实现特定结构的DLL,我用了一个叫 x64.nsh 。 The problem I had seemed to be with Audiere.Net.dll, but was actually caused by a problem with libaudieresharpglue.dll. I use NSIS for installers. To accomplish the architecture specific DLL, I used a header called x64.nsh.