NUnit 单元测试在测试类中找不到非托管 dll
我有以下情况:
我有一个可以运行的delphi dll(非托管)。我有一个可以运行的 win forms 应用程序(概念验证应用程序)。该 dll(及其所有依赖项)被复制到应用程序的 Bin/Debug 目录中。
我创建了一个 .NET 托管库,其中有一个类是 dll 的包装器。 dll 和 dll 的所有依赖项都复制到 /Bin/Debug 文件夹中。
在我的托管库的单元测试项目中,我为包装类创建了一个单元测试。当我运行单元测试时,显示以下错误:
DAEcommerce.Logic.Tests.Infrastruct.L3.L3DatabaseConnectionTest.OpenClose_ProperParameters_ActiveSetToTrueAndFalse: System.DllNotFoundException:无法 加载DLL'AttrbInterface.dll':A 动态链接库(DLL) 初始化例程失败。 (HRESULT 异常:0x8007045A)
有问题的 dll 被复制到单元测试项目的 Bin/Debug 文件夹中。我也尝试过将其复制到 Windows/system32,将其添加到 Windows 路径并将其复制到 NUnit exe 所在的文件夹中。它就是行不通。
我有以下问题:
- 问题是什么?
- 我怎样才能找到问题所在?
- 我该如何解决它。
I'have the following situation:
I have a delphi dll (unmanaged) that works. I have a win forms application (a proof of concept application) that works. The dll (and all its dependencies) are copied in the Bin/Debug directory of the application.
I've createad a .NET managed library which has a class that is a wrapper around the dll. all the dependencies of the dll and the dll are copied in the /Bin/Debug folder.
In my unit test project for the managed library I've created a unit test for the wrapper class. When I run the unit test the following error is shown:
DAEcommerce.Logic.Tests.Infrastructure.L3.L3DatabaseConnectionTest.OpenClose_ProperParameters_ActiveSetToTrueAndFalse:
System.DllNotFoundException : Unable
to load DLL 'AttrbInterface.dll': A
dynamic link library (DLL)
initialization routine failed.
(Exception from HRESULT: 0x8007045A)
The dll in question is copied in the Bin/Debug folder of the unit test project. I've tried also copying it to Windows/system32, adding it to the windows path and copying it in the folder where the NUnit exe is located. It just doesn't work.
I have the following questions:
- What is the problem?
- How can I found what is the problem?
- How can I fix it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 64 位系统上使用 7z.dll 和 SevenZipSharp 时遇到了类似的问题。 7z.dll 是 32 位的,因此我必须确保使用
nunit-x86.exe
。我还必须在 NUnit 设置中关闭卷影复制,不知道为什么,但否则它不会加载 7z.dll。I had a similar issue with 7z.dll and SevenZipSharp on a 64-bit system. 7z.dll was 32-bit, so I had to make sure that
nunit-x86.exe
is used. I also had to turn off shadow copying in NUnit settings, not sure why, but it wouldn't load 7z.dll otherwise.尝试使用 Windows SDK 中的 Fusion Log Viewer 实用程序来获取有关加载 .NET 程序集时实际发生情况的更多信息。
Try using the Fusion Log Viewer utility to from the Windows SDK to obtain more information about what's actually happening when your .NET assembly is loaded.