I get the Oops! code message when submitting the question below, any idea why?
Oops! Your question couldn't be submitted because:
Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon.
Moq throws a TypeInitializationException when using Moles with the [HostType("Moles")]. Code example and exception below.
[TestMethod]
[HostType("Moles")]
public void TestMethod()
{
var mock = new Mock<IAnything>();
}
The exception:
<pre>
System.TypeInitializationException occurred
Message=The type initializer for 'Moq.Extensions' threw an exception.
Source=Moq
TypeName=Moq.Extensions
StackTrace:
at Moq.Extensions.IsMockeable(Type typeToMock)
at Moq.Mock`1.CheckParameters()
at Moq.Mock`1..ctor(MockBehavior behavior, Object[] args)
at Moq.Mock`1..ctor(MockBehavior behavior)
at Moq.Mock`1..ctor()
at BP.DFR.Common.Services.Network.DfrNetworkQueryTests.MyTestMethod()
InnerException: System.Security.VerificationException
Message=Operation could destabilize the runtime.
Source=Moq
StackTrace:
at Moq.Extensions..cctor()
InnerException:
</pre>
The link below suggested it might be a moq version issue, but it happens in both version 3.1 and 4.0 for me.
http://code.google.com/p/moq/issues/detail?id=344
I'm using VS 2010 Premium SP1. Anybody had any luck resolving this?