如果 x86 构建,Nunit.exe 无法在 Vista 64 位上运行
我使用的是 Vista 64 位,并且我有一个使用 x86 配置构建的项目。 一切工作正常。 现在,我们正在创建测试。 我们有 NUnit 2.4.8,但有很多问题。
当我们直接选择 .dll 时,测试通过 Nunit.exe (gui) 加载,但在执行时出现 system.badimageformatException。
我通过在 Google 上搜索阅读了一些有关 nunit.exe.config 的技巧,但没有任何效果。 (更改为 UTF8...取消注释 .net 版本以启动)。
任何想法?
更新
我已经清理了解决方案并删除了所有 BIN 文件夹。 现在,当我编译时,我清楚地看到 bin 目录中只有 /x86/,而不是 x64 中的旧 /debug/。
当我使用 Nunit 时,出现异常(在加载中): System.IO.FileNotFoundException...
服务器堆栈跟踪: 在 System.Reflection.Assembly._nLoad(AssemblyName fileName、字符串 codeBase、证据 assemblySecurity、程序集位置Hint、StackCrawlMark& stackMark、布尔值 throwOnFileNotFound、布尔值 forIntrospection) 在 System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef、证据 assemblySecurity、StackCrawlMark& stackMark、布尔值 forIntrospection) 在 System.Reflection.Assembly.InternalLoad(字符串 assemblyString,证据 assemblySecurity,StackCrawlMark& stackMark,布尔值 forIntrospection) 在 System.Reflection.Assembly.Load(字符串 assemblyString) 在 NUnit.Core.Builders.TestAssemblyBuilder.Load(字符串路径) 在 NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, Boolean autoSuites) 在 NUnit.Core.Builders.TestAssemblyBuilder.Build(字符串程序集名称,字符串测试名称,布尔 autoSuites) 在NUnit.Core.TestSuiteBuilder.BuildSingleAssembly(TestPackage包) 在NUnit.Core.TestSuiteBuilder.Build(TestPackage包) 在NUnit.Core.SimpleTestRunner.Load(TestPackage包) 在NUnit.Core.ProxyTestRunner.Load(TestPackage包) 在NUnit.Core.ProxyTestRunner.Load(TestPackage包) 在NUnit.Core.RemoteTestRunner.Load(TestPackage包) 在System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md,Object [] args,对象服务器,Int32 methodPtr,布尔fExecuteInContext,Object []&outArgs) 在 System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
在 [0] 重新抛出异常: 在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg) 在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&msgData,Int32类型) 在NUnit.Core.TestRunner.Load(TestPackage包) 在NUnit.Util.TestDomain.Load(TestPackage包) 在 NUnit.Util.TestLoader.LoadTest(String testName)
Update 2
我正在使用我已修改为 x86 而不是 x64 的任何 CPU 进行编译。 原因是 调试。 这已经在前面的链接中讨论过。 我必须确认 NUnit 正在 64 位 mod 和 Corflags.exe 中运行
I am on Vista 64 bits and I have a project built with x86 configuration. All work fine. Now, we are at the time to create test. We have NUnit 2.4.8 but we have a lot of problem.
The test are loading trough the Nunit.exe (gui) when we select the .dll directly but when executing we have a system.badimageformatexception.
I have read by searching on Google few trick about the nunit.exe.config but none work. (changing to UTF8... uncomment .net version for startup).
Any idea?
Update
I have clean the solution and erase all BIN folder. Now when I compile I clearly see that I have only the /x86/ in the bin directory and not the old /debug/ that was in x64.
When I go with Nunit I have an exception (in the loading) : System.IO.FileNotFoundException...
Server stack trace:
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at NUnit.Core.Builders.TestAssemblyBuilder.Load(String path)
at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, Boolean autoSuites)
at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, String testName, Boolean autoSuites)
at NUnit.Core.TestSuiteBuilder.BuildSingleAssembly(TestPackage package)
at NUnit.Core.TestSuiteBuilder.Build(TestPackage package)
at NUnit.Core.SimpleTestRunner.Load(TestPackage package)
at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
at NUnit.Core.RemoteTestRunner.Load(TestPackage package)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at NUnit.Core.TestRunner.Load(TestPackage package)
at NUnit.Util.TestDomain.Load(TestPackage package)
at NUnit.Util.TestLoader.LoadTest(String testName)
Update 2
I am compiling with ANY CPU that I have modified to be x86 instead of x64. The reason is for the debug. This has been already discussed in the previous link. I have to confirm that NUnit is running in 64bits mod and Corflags.exe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
好的,我在这个
谢谢大家
Ok I found the solution in this website. You have to use the \NUnit-2.4.8\bin\nunit-x86.exe instead of \NUnit-2.4.8\bin\nunit.exe... didn't know that the \bin\ had 2 nunit!!!
Thx all
NUnit 主机可能作为 64 位进程运行(您可以通过查看任务管理器来确认)。 如果您的程序集仅为 x86,那么它将无法在该进程中运行。
您可以尝试在 NUnit 可执行文件上运行 corflags使用 /32bit+ 标志强制它运行 x86
The NUnit host is likely running as a 64 bit process (you can confirm that by looking in task manager). If you assembly is x86 only then it won't be able to run in that process.
You can try running corflags on the NUnit executable to force it to run x86, using the /32bit+ flag
在 MSBuild 运行平台设置为 x86 的 x64 构建服务器上从 TeamCity 3.1 升级到 4.0 时,也可能会发生这种情况。 TeamCity 运行程序在 4.0 中默认的平台似乎与 3.1 不同,没有考虑到构建运行 x86 的事实。
就我而言,第一个有效的修复是将平台覆盖添加到我的 MSBuild 脚本中的 NUnit 调用中:(
即,像其他建议中那样强制使用 32 位的 TeamCity 测试运行程序方式)
(这包括当测试程序集是任何 CPU(尽管我已将它们显式设置为 x86,因为某些测试动态加载仅限于 x86 的 DLL))。
This can also happen when upgrading from TeamCity 3.1 to 4.0 on an x64 build server with the MSBuild Run Platform set to x86. The TeamCity runner seems to default the platform differently in 4.0 than 3.1, not honouring the fact that the build is running x86.
In my case, the first fix that worked was adding a Platform override to the NUnit call in my MSBuild script:
(i.e., the TeamCity test runner way of forcing 32 bit as in the other suggestions)
(This includes when the platform target for the test assembly is Any CPU (although as it happens I have set them to x86 explicitly as some tests dynamically load DLLs that are constrained to x86)).
为什么使用 x86 配置而不是任何 CPU?
我想象当您加载 NUnit 时,它是使用 Any CPU 选项构建的,因此可以对 x64 代码进行 JIT。 当它尝试加载专门编译为 x86 运行的测试时,它会抛出异常。
我会尝试将所有配置设置更改为“任何CPU”,看看这是否可以解决您的问题。
Why are you using the x86 configuration and not Any CPU?
I'd imagine that when you load NUnit it's been built with the Any CPU option, so JITs to x64 code. When this tries to load your tests which are specifically compiled to run as x86 it throws the exception.
I'd try changing all your configuration settings to Any CPU and see if this solves your problem.
如果使用 TeamCity,您可以将值为 x86 的属性 teamcity.dotnet.nant.nunit2.platform 添加到 TeamCity 项目配置设置中的构建参数(在 Properties 中)和环境变量部分)。
If using TeamCity, you can add the property teamcity.dotnet.nant.nunit2.platform with the value x86 to the Build Parameters in your TeamCity project's configuration settings (in the Properties and Environment Variables section).
TeamCity 8.1 也有同样的问题。 解决这个问题的方法是将 NUnit 构建步骤 .NET Runtime / 平台: 更改为 x86
我还必须更改 运行测试:< /strong> 从 TestProject\bin\Release 到 TestProject\bin\x86\Release 的路径
Had the same problem with TeamCity 8.1. What solved it was changing NUnit build step .NET Runtime / Platform: to x86
I also had to change Run tests from: path from TestProject\bin\Release to TestProject\bin\x86\Release