3
votes

When i try to setup the the moq object like this:

mock.Setup(reader => reader.listOFs(1)).Returns(new List<IIAM_OF_Event>() { new IIAM_OF_Event() { ID = 11 } }.AsQueryable());

It throws

System.TypeInitializationException: The type initializer for 'Moq.ProxyFactory' threw an exception. ---

System.TypeInitializationException: The type initializer for 'Moq.CastleProxyFactory' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'Castle.Core, Version=4.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) ---> System.IO.FileLoadException: Could not load file or assembly 'Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

IIAM_OF_Event is an Linq table.

1
Try reinstalling the Moq NugetNkosi
In my case, versions of the Castle.Core and Castle.Windsor in the test project were different from the target project. Check that one.hakan

1 Answers

3
votes

Somehow one component integrated in the test was asking for version Castle.Core 4.1.0.0 but was version 4.0.0.0 that was included in build.

I added this to the config file:

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>
...