When I try using unit tests (Microsoft vs2010-embedded testing framework) with MVC3, all unit tests that instantiate a controller throw the following error:
Test method CleanTestMVC.Tests.Controllers.HomeControllerTest.About threw exception:
System.Security.VerificationException: Operation could destabilize the runtime.
It seems to be not project-specific: I have created a new MVC3 project with an internet application template and the default auto-generated tests for it and those don’t run as well. I’ve tried recreating the problem on a colleague’s machine (identical settings) and his machine seem to create same issues.
No references or external libraries were added for those projects, but both computers do have TypeMock installed, although not referenced and disabled in the options (I’ve heard people blaming it for similar issues).
Could anybody please suggest something? A workaround and/or a potential cause? It is the first time I use MVC3 with unit testing and nobody around have ever worked with MVC3 and this is a “guinea-pig” project for it.
Thanks for the help!
Update: After trying it at my home PC everything works there even though I also have TypeMock (trial) installed.
Update 2: The stack trace for the problem:
System.Web.Mvc.Controller..ctor()
CleanTestMVC.Controllers.HomeController..ctor()
CleanTestMVC.Tests.Controllers.HomeControllerTest.About()
Ok so in the end it turned out that the company had an older version of Typemock installed, which was incompatible with MVC3. Disabling Typemock through the Typemock->Disable Typemock didn’t actually “fully” disable it, it had to be unchecked in “tools/Addin Manager”. After updating Typemock to the latest version the problem is solved.