Moq.CastleProxyFactory'无法加载文件或程序集'Castle.Core [英] Moq.CastleProxyFactory' Could not load file or assembly 'Castle.Core
问题描述
当我尝试像这样设置moq对象时:
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());
抛出
System.TypeInitializationException:'Moq.ProxyFactory'的类型初始值设定项引发了异常. ---
System.TypeInitializationException: The type initializer for 'Moq.ProxyFactory' threw an exception. ---
System.TypeInitializationException:'Moq.CastleProxyFactory'的类型初始值设定项引发了异常. ---> System.IO.FileLoadException:无法加载文件或程序集"Castle.Core,Version = 4.1.0.0,Culture = neutral,PublicKeyToken = 407dd0808d44fbdc"或其依赖项之一.找到的程序集的清单定义与程序集引用不匹配. (来自HRESULT的异常:0x80131040)---> System.IO.FileLoadException:无法加载文件或程序集"Castle.Core,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 407dd0808d44fbdc"或其依赖项之一.找到的程序集的清单定义与程序集引用不匹配. (来自HRESULT的异常:0x80131040)
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
是Linq表.
推荐答案
以某种方式,测试中集成的一个组件要求版本Castle.Core 4.1.0.0,但版本4.0.0.0已包含在构建中.
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>
...
这篇关于Moq.CastleProxyFactory'无法加载文件或程序集'Castle.Core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!