Moq unit tests : System.TypeInitializationException on Moq.Proxy.CastleProxyFactory
<p>I'm using Moq as a mocking Library for my unit tests. </p>

<p>It seems it has a hard time finding the Castle Windsor libraries, as it gives me this error : </p>

<pre><code>System.TypeInitializationException : Une exception a été levée par l'initialiseur de type pour 'Moq.Mock`1'.
  ----&gt; System.TypeInitializationException : Une exception a été levée par l'initialiseur de type pour 'Moq.Proxy.CastleProxyFactory'.
  ----&gt; System.IO.FileNotFoundException : Impossible de charger le fichier ou l'assembly 'Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' ou une de ses dépendances. Le fichier spécifié est introuvable.
   à Moq.Mock`1.&lt;InitializeInstance&gt;b__24_0()
   à Moq.PexProtector.Invoke(Action action)
   à Moq.Mock`1.InitializeInstance()
   à Moq.Mock`1.OnGetObject()
   à Moq.Mock.GetObject()
   à Moq.Mock.get_Object()
   à Moq.Mock`1.get_Object()
   à TecLib.Common.Tests.Infrastructure.CqrsRepositoryBaseTest.SetUp() dans C:\Users\Ludovic\Documents\Visual Studio 2015\Projects\TEC2\TecLib.Common.Tests\Infrastructure\CqrsRepositoryBaseTest.cs:ligne 38
--TypeInitializationException
   à Moq.Proxy.CastleProxyFactory..ctor()
   à Moq.Mock`1..cctor()
--FileNotFoundException
   à Moq.Proxy.CastleProxyFactory..cctor()
</code></pre>

<p>This is one of the tests that trigger the error. The code works perfectly fine. It's the Moq Library that triggers the error as it seems to not be able to find the Castle Windsor Library for some reason.</p>

<pre><code>    [SetUp]
    public void SetUp()
    {
        _eventStore = new Mock&lt;IEventStore&gt;();
        _eventDispatcher = new Mock&lt;IEventDispatcher&gt;();
        _entityFactory = new Mock&lt;IEntityFactory&gt;();

        _repository = new CqrsAddressRepository(_entityFactory.Object, _eventStore.Object, _eventDispatcher.Object);
        _addressInfo1 = new AddressInfo("400 chemin Jette", "", "", "Farnham", "J0J2B0", "Quebec", "Canada");
        _addressInfo2 = new AddressInfo("322 rue Principale E", "", "", "Farnham", "J2N1L7", "Quebec", "Canada");
    }
</code></pre>

<p>These are my packages for that project</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;packages&gt;
  &lt;package id="Castle.Core" version="3.3.3" targetFramework="net461" /&gt;
  &lt;package id="Castle.Windsor" version="3.3.0" targetFramework="net461" /&gt;
  &lt;package id="Moq" version="4.5.21" targetFramework="net461" /&gt;
  &lt;package id="NUnit" version="3.4.1" targetFramework="net461" /&gt;
&lt;/packages&gt;
</code></pre>

<p>These tests worked perfectly before. I have no idea what has changed that make them throw this error now.</p>

<p>Maybe installation of the 4.6.1 .net Framework ?</p>

<p>Please help!</p>