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

查看:123
本文介绍了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上)

  • 是否需要更改集成测试项目的构建属性?

  • 是否需要更改解决方案的配置设置?

  • Do I need a different nUnit assembly?
  • Do I need to change the Solution Platform setting in VS2010? (It's currently on "Any CPU")
  • Do I need to change build properties of my integration tests project?
  • Do I need to change configuration settings of my solution?

不幸的是,我不需要目前有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.

一个中间的解决方法是将SQLite DLL替换为64位的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天全站免登陆