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.