Moq.CastleProxyFactory' Could not load file or assembly 'Castle.Core

吃可爱长大的小学妹 提交于 2019-12-24 04:43:04

问题


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:


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>
...


来源:https://stackoverflow.com/questions/52480119/moq-castleproxyfactory-could-not-load-file-or-assembly-castle-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!