64 位机器上的 nUnit 异常 [英] nUnit Exception on a 64 bit Machine

查看:23
本文介绍了64 位机器上的 nUnit 异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 MVC 3.0 应用程序.我的测试框架是 nUnit 2.4.8.0.我在 32 位机器上开始这段代码,最近开始使用 64 位机器.我刚刚将项目升级到 .NET 4.0.

I have an MVC 3.0 app. My testing framework is nUnit 2.4.8.0. I started this code on a 32 bit machine, and recently started using a 64 bit machine. I just as recently upgraded the project to .NET 4.0.

我的应用程序运行良好 - 我能够适当地从数据库中提取对象.问题在于我何时运行集成测试.

My application runs fine - I am able to hydrate my objects from the database appropriately. The issue is when I run my integration tests.

测试失败,并给出一个我以前从未见过的异常​​:

The tests fail, and give an exception I've never seen before:

NHibernate.ADOException : cannot open connection
  ----> System.BadImageFormatException : An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

我已经在网上搜索过这个异常——这当然是 nUnit 的问题,尽管有 NHibernate 异常(请记住,NHibernate 允许我在运行应用程序时对对象进行水合和持久化).

I've searched online for this exception - It's of course a problem with nUnit, despite the NHibernate exception (remember, NHibernate allows me to hydrate and persist objects when I run the app).

我将我的 nUnit 程序集升级到最新版本 2.5.10,并将项目中的引用更新到 nUnit zip 文件的net-2.0"文件夹下的程序集.我再次运行测试,并收到相同的异常.

I upgraded my nUnit assembly to the most recent release, version 2.5.10, and updated the reference in the project to the assembly under the 'net-2.0' folder of the nUnit zip file. I ran the tests again, and received the same exception.

程序集、代码和 ASP.NET 开发服务器之间似乎存在某种 32 位与 64 位冲突.

It seems that there is some sort of 32-bit vs 64-bit conflict between assemblies, code, and the ASP.NET Development Server.

我没有处理 32 位与 64 位问题的任何经验,所以我不知道是否还有其他相关的堆栈溢出问题(我见过的问题似乎没有).我有一些想法,但没有答案:

I don't have any experience dealing with 32-bit vs 64-bit issues, so I don't know if there are other questions on stack overflow that are relevant (the ones I've seen seem not to be). I have some ideas, but no answers:

  • 我需要不同的 nUnit 程序集吗?
  • 我是否需要更改 VS2010 中的解决方案平台设置?(它目前在任何 CPU"上)
  • 我是否需要更改集成测试项目的构建属性?
  • 我需要更改解决方案的配置设置吗?

不幸的是,我目前没有 32 位机器来测试代码.上述问题中是否有解决此问题的正确方法?你能提供任何指导吗?

Unfortunately I don't have a 32-bit machine around to test the code on at the moment. Are any of the above questions on the right path to solving this? Can you offer any guidance?

谢谢.

更新:我真的希望能够使用 TestDriven.NET 从 Visual Studio 中运行测试.我不想开始使用 nunit UI 来运行我的测试.

UPDATE: I'm really hoping to be able to run the tests from within Visual Studio using TestDriven.NET. I don't want to have to start using the nunit UI to run my tests.

更新 2:对不起,我可能没有说清楚.我还没有使用TestDriven.NET,我说的是我希望使用它,但我还没有在新的x64机器上安装它.此时,我正在尝试通过单击 Visual Studio IDE 中的可视图标来运行测试,如下图所示:

UPDATE 2: Sorry, I may not have been clear. I'm not yet using TestDriven.NET, what I said is that I'm hoping to use it, but I haven't installed it yet on the new x64 machine. At this moment, I'm trying to run the tests by clicking on the visual icon inside the Visual Studio IDE, as in the image below:

执行该操作后,测试失败,弹出的对话框显示以下内容:

Following through with that action, the tests fail, and the dialog that pops up displays the following:

这是我上面引用的例外.没有对尚未加载的程序集的引用.

That is the exception that I quoted up above. There is no reference to assemblies that haven't loaded.

起初我不相信我使用的 NHibernate (2.0.1.4000) 版本会很重要;我这样说是因为提供程序能够在应用程序运行时从数据库中返回所需的对象.但是,当我调试测试时,我看到在我的提供程序中抛出了异常.当深入挖掘时,这似乎是我的 SQLite 程序集的来源.但同样,这是在我运行项目时工作的同一个程序集 - 为什么在我运行集成测试时它不起作用?

At first I didn't believe that the version of NHibernate (2.0.1.4000) I am using would matter; I say this because the providers are able to return the desired objects from the database when the app is run. However, When I debug the test, I see that the exception is being thrown in my provider. When digging down a bit, It seems the source of this is my SQLite assembly. But again, this is the same assembly that works when I run the project - why would it not work when I run the integration tests?

推荐答案

这是我经常遇到的问题.

This is a problem I get regularly.

System.Data.SQLite 是 32 位或 64 位特定程序集,因为它在 DLL 内捆绑了 SQLite 的本机映像.NUnit 测试运行器试图以错误的模式运行它,即在 32 位测试运行器中运行 64 位程序集,并且当它尝试对 SQLite C API 进行本机调用时会发生故障.Windows 无法做到这一点.

System.Data.SQLite is a 32 or 64 bit specific assembly as it bundles a native image for SQLite inside the DLL. The NUnit test runner is trying to run it in the wrong mode i.e. a 64-bit assembly in a 32-bit test runner and it's going bang when it tries to make a native call to the SQLite C API. Windows can't do that.

我建议您在 32 位或 64 位(即您的开发环境和部署环境)上跨所有平台进行标准化.

I suggest you standardise across all platforms on either 32-bit or 64-bit i.e. your dev environment and your deployment environment.

一个中间修复程序是用 64 位的 DLL 替换 SQLite DLL,可从此处获得:http://system.data.sqlite.org/.然而,这可能会在部署时中断,此时您需要为您的实时环境创建一个构建配置,该配置提供正确的 DLL 版本(32/64 位).

An intermediate fix will be to replace the SQLite DLL with a 64-bit one as available from here: http://system.data.sqlite.org/. this may however break at deploy time at which point you will need to create a build configuration for your live environment which ships the right DLL version (32/64-bit).

让 NUnit 确定性地在 32 位或 64 位模式下运行是一件痛苦的事情,所以我不会亲自操心.

Getting NUnit to deterministically run in either 32 or 64 bit mode is a pain so I wouldn't bother with that personally.

这篇关于64 位机器上的 nUnit 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆