gpt4 book ai didi

.net - 自动夹具和最小起订量 v4

转载 作者:行者123 更新时间:2023-12-04 00:48:16 25 4
gpt4 key购买 nike

我使用 Nuget 安装了 Autofixture 和 Moq。所以我有 moq 版本 4。

运行以下代码时

var fixture = new Fixture().Customize(new AutoMoqCustomization());
fixture.CreateAnonymous<ISomething>();

出现以下错误

System.IO.FileLoadException : Could not load file or assembly 'Moq, Version=3.1.416.3, Culture=neutral, PublicKeyToken=69f491c39445e920'



我也尝试将其重定向到 v4,但没有运气。
<configuration>
<runtime>
<assemblyBinding>
<dependentAssembly>
<assemblyIdentity name="Moq" publicKeyToken="69f491c39445e920" culture="neutral"/>
<bindingRedirect oldVersion="3.1.416.3" newVersion="4.0.10827.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

这里可能是什么问题?

最佳答案

为了重定向配置文件中的程序集绑定(bind),您需要指定 urn:schemas-microsoft-com:asm.v1 <assemblyBinding> element 中的命名空间,就像在这个例子中:

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Moq"
publicKeyToken="69f491c39445e920"
culture="neutral"/>
<bindingRedirect oldVersion="3.1.416.3"
newVersion="4.0.10827.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

有趣的是,使用早期版本的 .NET 编译的库程序集(例如 Moq 3AutoFixture 2.1 )将自动加载到在 .NET 4.0 上运行的进程中,因为 In-Process Side-by-Side execution .这是来自 MSDN 的关于此的引用:

If an application is compiled using the .NET Framework 4 runtime but includes a library that was built using an earlier runtime, that library will use the .NET Framework 4 runtime as well. However, if you have an application that was built using an earlier runtime and a library that was built using the .NET Framework 4, you must force your application to also use the .NET Framework 4



相关资源:
  • Redirecting Assembly Versions
  • 关于.net - 自动夹具和最小起订量 v4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6505591/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com