3

[HostType("Moles")]Moq 在将 Moles 与该属性一起使用时会引发 TypeInitializationException 。下面的代码示例和异常。

[TestMethod]
[HostType("Moles")]
public void TestMethod()
{
    var mock = new Mock<IAnything>();
}

例外:

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:

下面的链接表明它可能是最小起订量版本问题,但对我来说,它发生在 3.1 和 4.0 版本中。

http://code.google.com/p/moq/issues/detail?id=344

我正在使用 VS 2010 Premium SP1。有人有运气解决这个问题吗?

4

0 回答 0