我正试图运行一个使用Moq的单元测试.问题是我一直得到与Visual studio 2019的follerwing。
讯息:System.TypeInitializationException : The type initializer for 'Moq.DefaultValueProject': 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. 被定位的汇编的清单定义与汇编引用不匹配。(来自HRESULT的异常:0x80131040)
我正在使用最新版本的Moq 4.13.1和System.Threading.Tasks.Extensions v.4.5.3是否有任何特定版本的System.Threading.Tasks.Extensions或.NET应该与Moq一起使用?
你可以在你的测试项目中添加一个应用程序配置文件(App.config),并执行绑定重定向到当前安装的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>