无法加载文件或程序集 System.Threading.Tasks,版本 = 2.5.19.0 [英] Could not load file or assembly System.Threading.Tasks, Version=2.5.19.0

查看:21
本文介绍了无法加载文件或程序集 System.Threading.Tasks,版本 = 2.5.19.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WPF (.NET 4) 项目,使用 google url shorter API,我已经通过 nugget https://www.nuget.org/packages/Google.Apis.Urlshortener.v1/1.7.0.25-beta

I have a WPF (.NET 4) project using google url shortener API, I have installed the client library through nugget https://www.nuget.org/packages/Google.Apis.Urlshortener.v1/1.7.0.25-beta

该应用程序在 Visual Studio 中运行良好,但一旦发布就会引发异常无法加载文件或程序集 System.Threading.Tasks,版本 = 2.5.19.0这个程序集和所有其他程序集都存在于安装文件夹中,并随应用程序一起发布.我在互联网上搜索过,有人建议在 app.config 中手动绑定依赖库,但它仍然不起作用,因为 app.config 中已经提到了我的所有依赖库,下面是我的 app.config 的样子

the application works fine in visual studio but once published it throws the exception Could not load file or assembly System.Threading.Tasks, Version=2.5.19.0 this and all other assemblies are present in the installation folder, and it gets publish with application. I have searched internet and people suggest to manually bind the dependency libraries in the app.config, it still does not work as all of my dependency libraries are already mentioned in app.config, below is how my app.config looks like

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-1.2.13.0" newVersion="1.2.13.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Threading.Tasks.Extensions.Desktop" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-1.0.165.0" newVersion="1.0.165.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

推荐答案

您可以从 Microsoft BCL 团队博客开始,通过删除错误条目来清理 app.config

You might start from Microsoft BCL team blog and clean up the app.config by removing the wrong entries,

http://blogs.msdn.com/b/bclteam/p/asynctargetingpackkb.aspx(存档)

问题 6

症状

将 NuGet 包添加到其他项目使用的项目时使用不同目标框架的项目,您可能会看到警告类似于以下内容:

When adding the NuGet package to a project that is consumed by another project with a different target framework you might see warnings similar to the following:

主要参考Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"无法解析,因为它间接依赖于框架程序集System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"在当前的目标框架中无法解决..NETFramework,Version=v4.5".要解决此问题,请删除引用Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"或将您的应用程序重定向到包含System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"的框架版本.

主要参考Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"无法解析,因为它间接依赖于框架程序集System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"在当前的目标框架中无法解决..NETFramework,Version=v4.5".要解决此问题,请删除参考Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"或将您的应用程序重定向到包含System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"的框架版本.

解决方案

问题是 NuGet 添加了不正确的绑定重定向平台组件.要删除它们,请打开 app.config导致警告并删除突出显示的项目条目 [由 ***** 注释]:

The problem is that NuGet added incorrect binding redirects for platform assemblies. To remove them, please open the app.config for the project that caused the warnings and remove the highlighted entries [noted by *****]:

<?xmlversion="1.0"encoding="utf-8"?>
<configuration>
    <runtime>
        <assemblyBindingxmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>******
                <assemblyIdentityname="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <bindingRedirectoldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
            </dependentAssembly> .
            <dependentAssembly>******
                <assemblyIdentityname="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <bindingRedirectoldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
            </dependentAssembly>
            </assemblyBinding>
    </runtime>
</configuration>


评论:


Commentary:

随着 .NET Framework 4.0 的终止,您在自己使用异步目标包之前应该三思而后行.如果此依赖项来自 NuGet 包,您还应检查 NuGet 包是否有没有此类依赖项的较新版本.

With .NET Framework 4.0 end-of-life, you should think twice before using the async targeting pack yourself. If this dependency comes from a NuGet package, you should also check whether the NuGet package has a newer version that has no such dependency.

这篇关于无法加载文件或程序集 System.Threading.Tasks,版本 = 2.5.19.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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