title: MOQ 4.0: The type initializer for 'Moq.Mock`1' threw an exception
body: <p>I'm getting the exception </p>
  
  <blockquote>
    <p>The type initializer for 'Moq.Mock`1'
    threw an exception.</p>
  </blockquote>
  
  <p>using Moq 4.0 I've checked around on a couple of forums and they allude to using the Moq-NoCastle version.  I've tried both this and version in the Moq folder.  Both with the same result.</p>
  
  <p>I've got a solution with 2 projects, one for my interface, one for my tests.  My main project has 2 files:</p>
  
  <p>IMyInterface.cs:</p>
  
  <pre><code>using System;
  
  namespace Prototype
  {
      public interface IMyInterface
      {
          int Value { get; set; }
          void ProcessValue();
          int GetValue();
      }
  }
  </code></pre>
  
  <p>My program.cs file has just the default code that's generated with the project.</p>
  
  <p>My test project has a single file for my dummy test - TestProgram.cs</p>
  
  <pre><code>using System;
  using NUnit.Framework;
  using Moq;
  
  namespace Prototype.UnitTests
  {
      [TestFixture]
      public class TestProgram
      {
          Mock&lt;IMyInterface&gt; mock;
  
          [TestFixtureSetUp]
          void TestSetup()
          {
              mock = new Mock&lt;IMyInterface&gt;();
              mock.Setup(x =&gt; x.GetValue()).Returns(2);
          }
  
          [Test]
          public void RunTest()
          {
              IMyInterface obj = mock.Object; /* This line fails */
              int val = obj.GetValue();
              Assert.True(val == 2);
          }
      }
  }
  </code></pre>
  
  <p>According to the documentation all is good and proper, and it compiles nicely.  The problem comes when I try to run the test.  It gets to the line marked above and crashes with the exception:</p>
  
  <blockquote>
    <p>The type initializer for 'Moq.Mock`1'
    threw an exception.</p>
  </blockquote>
  
  <p>I can't see what's going wrong here, can anyone shed some light on it?</p>