Operation Could Destabilize The Runtime Using Fakes
Tuesday, 23rd October 2012
A while ago I wrote about Fakes, Stubs and Shims in Visual Studio and I have been chewing my own dog food by using them, rather than a mocking framework in my recent work.
When faking your own classes and interfaces, there isn't much to talk about in this respect - things do seem to just work. The problems arise when you need to fake certain system classes, at which point you get the rather serious message:
Operation Could Destabilize The Runtime
I received this error when using a fakes assembly to stub an HttpControllerContext and an HttpActionDescriptor, both of which reside in the System.Web.Http.Controllers namespace. I have heard of similar issues in other System.Web namespaces, such as MVC.
There is actually an issue raised on Microsoft Connect for this error message. The only slight hitch is that it has been deferred. So I opted to remove the fakes from my test.
Removing the calls to the StubHttpControllerContext and StubHttpActionDescriptor is not enough! You will still get errors. You will need to completely remove the fakes and potentially restart visual studio to clear the issues!
In my case, I had to substitute the fakes for Rhino Mocks while I await for a fix or a work-around!