gpt4 book ai didi

c# - Moq 4.13.1 与 Task.Extensions 不兼容

转载 作者:行者123 更新时间:2023-12-03 14:23:22 27 4
gpt4 key购买 nike

我正在尝试运行使用 Moq 的单元测试。问题是我一直在使用 Visual Studio 2019。

Message: System.TypeInitializationException : The type initializer for 'Moq.DefaultValueProvider' threw an exception. ----> System.IO.FileLoadException : Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)



我正在使用最新版本的 Moq 4.13.1 和 System.Threading.Tasks.Extensions v.4.5.3
是否有任何特定版本的 System.Threading.Tasks.Extensions 或 .NET 应该与 Moq 一起使用?

最佳答案

您可以将应用程序配置文件添加到您的测试项目 (App.config) 并执行绑定(bind)重定向到当前安装的 System.Threading.Tasks.Extensions 版本,例如

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

关于c# - Moq 4.13.1 与 Task.Extensions 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60217316/

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