nunit on release build: “Common Language Runtime detected an invalid program.”

我怕爱的太早我们不能终老 提交于 2019-12-06 01:59:37

问题


I upgraded our software from vs2008/.net 3.5 to vs2010/.net 4.0. All third party libraries (most relevant: nhibernate 2.1.2 or 3.0.0, nunit 2.5.2) are still compiled using vs2008. When I run the unit tests for the debug build of our software, everything works fine. On the release build, nunit reports exceptions on 33 of 228 tests: System.InvalidProgramException : Common Language Runtime detected an invalid program. It always happens on the same tests, for both nunit-console and the Resharper 5.0 test runner. When I run them using the Resharper "debug unit-tests" command, all tests pass. It makes no difference whether I run the tests individually or batched. The exception always happens near nhibernate query calls, but I can't say for sure since the release build stack trace is somewhat sparse. It does not depend on the nhibernate bytecode generator, the same exception appears for castle and linfu. Does anyone have an idea how to debug this?

Edit: Removing Spring.NET had no effect on this issue.

Edit: When I switch the release config debug output to full instead of pdb only and deactivate the optimize code checkbox, the exception disappears. Both settings are required, if I change only one of them the bug remains. However, a different set of tests fail if I only change one. All class libraries are compiled for Any CPU.


回答1:


This is probably a stupid question: are you sure all of the assemblies are compiled to the same architecture (x86/x64)? I ran into this once a while back.




回答2:


I had something similar when i selected "NET Framework 4.0 Client Profile". Try to change the target framework to "NET Framework 4.0"




回答3:


My application would also run in debug but crash with that same exception on release configuration. The cause was that I had a method with the conditional "DEBUG" attribute, which returned a value...

Of course, in release config, all methods with the conditional "DEBUG" attribute are changed into stubs with no return value. So the IDE might think your types are fine gong by the code analysis and offer no warning, but the compiled application has return type miss-matches!

Just thought I'd add this for those banging their heads against a wall with this issue.



来源:https://stackoverflow.com/questions/3251433/nunit-on-release-build-common-language-runtime-detected-an-invalid-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!