I have a unit test for SharePoint 2010 code. SharePoint 2010 is .Net 3.5 64-bit system. When I run this test with the test runner I get "Microsoft SharePoint is not supported with version 4.0.30319.1 of the Microsoft .Net Runtime" exception.System.PlatformNotSupportedException".
The reason I think it is related to CodeRush is because the same test runs well under nUnit GUI or from console app. Is is possible that the call comes from CodeRush .Net 4.0 assembly and if it is, can I change it to framework 3.5? (I could not find this option)
We cannot replicate this problem in our VS 2010 for a SharePoint 2010 VisualWebPartProject. All tests are run as expected via the Unit Test Runner. I've attached our test sample. Please feel free to modify it, if it's necessary to illustrate the problem.
Please take a look at the attached project. In order to run it you would need to download the latest version of nUnit and you also need to run on SharePoint server.
In the Visual Studio 2010 release, there is a limitation that prevents you from testing a SharePoint assembly using Visual Studio Unit Test. Unit tests created for Visual Studio Unit Test must be developed using .NET Framework 4.0 in Visual Studio 2010; whereas, SharePoint 2010 assemblies are based on .NET Framework 3.5. In many cases, this is not an issue—because, generally, .NET Framework 4.0 assemblies are compatible with .NET Framework 3.5 assemblies, so you can run a .NET Framework 4.0 test against a .NET Framework 3.5 assembly. However, the way in which SharePoint loads the .NET common language runtime (CLR) prevents the runtime from properly loading and running the tests within Visual Studio Unit Test.
This limitation prevents you from running integration tests with SharePoint within Visual Studio Unit Test. Integration tests execute real SharePoint API logic instead of substituting the logic with a test implementation. Two isolation tools discussed in the following sections, TypeMock and Moles, will continue to work because they intercept calls to the SharePoint API before the actual SharePoint logic is invoked. You can execute integration tests using a third-party framework such as xUnit or nUnit. Coded user interface (UI) tests against SharePoint applications will run without any issues from within Visual Studio 2010.
nUnit runs this test just fine, but the test runner does not. Having a test runner for SharePoint was my primary motiviation for using your product. I thought that it will not have the same limiation... Please don't tell me that it is not supported
Thank you for the additional details. I don't know if this is good news for you or not, but we've finally managed to replicate the problem. I'm forwarding it to our developers for further processing. Thank you for your patience.
Our developers have found the cause of the problem, and we're currently working on a fix.
However, we've also found a workaround. In order to resolve the problem immediately, please do the following:
1) Delete the C:\Program Files (x86)\DevExpress 2010.1\IDETools\System\CodeRush\Bin\Plugins\CR_ExtUnitTestRunnerNet4x64.exe file;
2) Rename the CR_ExtUnitTestRunnerx64.exe file located in the C:\Program Files (x86)\DevExpress 2010.1\IDETools\System\CodeRush\Bin\Plugins\ folder to CR_ExtUnitTestRunnerNet4x64.exe.
Please let us know whether this helps.
Your workaround works fine, thank you!
Thank you for the good news, Stan!