无法加载文件或程序集“System.ValueTuple, Version=0.0.0.0";或其依赖项之一 [英] Could not load file or assembly "System.ValueTuple, Version=0.0.0.0" or one of its dependencies

查看:24
本文介绍了无法加载文件或程序集“System.ValueTuple, Version=0.0.0.0";或其依赖项之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将我的项目更新到 .NET Standard 2.0,但在测试期间我发现了一个异常:

I tried to update my project to .NET Standard 2.0 and during testing I got catch an exception:

System.IO.FileLoadException:无法加载文件或程序集System.ValueTuple,Version=0.0.0.0,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51"或其依赖项之一.找到的程序集清单的定义与对程序集的引用不匹配.

System.IO.FileLoadException: 'Could not load file or assembly "System.ValueTuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" or one of its dependencies. The definition of the assembly manifest found does not match the reference to the assembly.

这在 package.config 中存在并存在于包的文件夹中.我尝试了一些版本的 System.ValueTuple 包,结果是一个.

This is assambly exists in package.config and exists on the package's folder. I tried some versions of System.ValueTuple package, result is one.

为什么依赖版本是«0.0.0.0»?

Why the version of dependencies «0.0.0.0»?

有人知道这个问题吗?

VS 2017 预览版、UnitTestApp、.NET Framework 4.7.

VS 2017 Preview, UnitTestApp, .NET Framework 4.7.

在单元测试应用程序中,我创建了 EF 模型(Microsoft.EntityFrameworkCore、Microsoft.EntityFrameworkCore.SqlServer 2.0.0-preview2-final,它需要在 .NET Standard 应用程序中).单元测试方法 - 使用 EF db 模型将一些行插入表中,然后调用savechanges",然后抛出此异常.

In the unit test app I create EF model (Microsoft.EntityFrameworkCore, Microsoft.EntityFrameworkCore.SqlServer 2.0.0-preview2-final, it needs in .NET Standard app). The Unit test method - insert into table some rows using EF db model, and call 'savechanges', after that throw this exception.

当我使用 EntityFrameworkCore 1.1.2(带有 EF 模型的 dll - 标准 1.4,单元测试框架 4.6.2)时 - 该测试运行良好.

When I used EntityFrameworkCore 1.1.2 (dll with EF model - Standard 1.4, unit test Framework 4.6.2) - this test worked well.

推荐答案

我通过启用 Automatic Binding Redirection 在我的 .NET Framework 4.7 项目(引用 .NET Standard 2.0 库).可以通过手动编辑项目的 .csproj 文件并添加以下片段来启用绑定重定向:Project 元素的子元素:

I solved this problem by enabling Automatic Binding Redirection in my .NET Framework 4.7 project (that references .NET Standard 2.0 library). Binding redirection can be enabled by manually editing project's .csproj file and addind following snippet a child of Project element:

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

Visual Studio 然后在构建期间生成必要的程序集重定向到项目的 app.config,类似于:

Visual Studio then during build generates neccessary assembly redirections to project's app.config, similar to this:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
  </dependentAssembly>
</assemblyBinding>

允许加载正确的程序集.

allowing correct assembly to be loaded.

这篇关于无法加载文件或程序集“System.ValueTuple, Version=0.0.0.0";或其依赖项之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆