无法加载文件或程序集System.Threading.Tasks,版本= 2.5.19.0加载、版本、文件、程序

2023-09-03 07:24:05 作者:◇.矢志不渝、

我使用谷歌URL缩短API一个WPF(.NET 4)项目中,我已经安装过金块https://www.nuget.org/packages/Google.Apis.Urlshortener.v1/1.7.0.25-beta

应用程序正常工作在Visual Studio中,但一旦公布就引发异常 无法加载文件或程序集System.Threading.Tasks,版本= 2.5.19.0 这和所有其他组件是present在安装文件夹,它得到发布与应用。我搜索互联网,人们建议手工绑定的app.config的依赖库,它仍然不为我所有的依赖库已经在app.config中提到的工作,下面是如何我的app.config的样子。

 <运行>
    < assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
      < dependentAssembly>
        < assemblyIdentity名=System.Runtime公钥=b03f5f7f11d50a3a文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-2.5.19.0NEWVERSION =2.5.19.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=System.Threading.Tasks公钥=b03f5f7f11d50a3a文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-2.5.19.0NEWVERSION =2.5.19.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=System.Net.Http公钥=b03f5f7f11d50a3a文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-2.1.10.0NEWVERSION =2.1.10.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=System.Net.Http.Primitives公钥=b03f5f7f11d50a3a文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-2.1.10.0NEWVERSION =2.1.10.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=log4net的公钥=669e0ddf0bb1aa2a文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-1.2.13.0NEWVERSION =1.2.13.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=Microsoft.Threading.Tasks.Extensions.Desktop公钥=b03f5f7f11d50a3a文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-1.0.165.0NEWVERSION =1.0.165.0/>
      < / dependentAssembly>
    < / assemblyBinding>
  < /运行>
 

请帮忙理清这个问题,我的应用程序已经准备好和它现在正在长了一点,只是把它发布。

解决方案

您可以从微软BCL团队博客启动和清理的app.config通过删除错误输入,

ASP.NET 运行时错误 未能加载文件或程序集

http://blogs.msdn.com/b/bclteam/p/ asynctargetingpackkb.aspx

  

第6期

     

症状

     

当添加的NuGet包到由另一个消耗项目   项目有不同的目标框架,你可能会看到警告   类似以下内容:

     

主要参考Microsoft.Threading.Tasks,版本= 1.0.12.0,   文化=中性公钥= b03f5f7f11d50a3a,   的ProcessorArchitecture = MSIL无法得到解决,因为它有一个   在框架组装间接依赖System.Runtime,   版本= 2.5.19.0,文化=中性公钥= b03f5f7f11d50a3a   这可能不是在当前的目标框架来解决。   .NETFramework,版本= V4.5。要解决此问题,请删除   参考Microsoft.Threading.Tasks,版本= 1.0.12.0,   文化=中性公钥= b03f5f7f11d50a3a,   的ProcessorArchitecture = MSIL或重新定位你的应用程序到   框架版本,其中包含System.Runtime,版本= 2.5.19.0,   文化=中性公钥= b03f5f7f11d50a3a。

     

主要参考Microsoft.Threading.Tasks.Extensions,   版本= 1.0.12.0,文化=中性公钥= b03f5f7f11d50a3a,   的ProcessorArchitecture = MSIL无法得到解决,因为它有一个   在框架组装间接依赖System.Runtime,   版本= 2.5.19.0,文化=中性公钥= b03f5f7f11d50a3a   这可能不是在当前的目标框架来解决。   .NETFramework,版本= V4.5。要解决此问题,请删除   参考Microsoft.Threading.Tasks.Extensions,版本= 1.0.12.0,   文化=中性公钥= b03f5f7f11d50a3a,   的ProcessorArchitecture = MSIL或重新定位你的应用程序到   框架版本,其中包含System.Runtime,版本= 2.5.19.0,   文化=中性公钥= b03f5f7f11d50a3a。

     

解决方案

     

的问题是,加入的NuGet不正确绑定重定向为   平台组件。要删除它们,请打开的app.config为   导致警告和删除突出显示的项目   项(计算器不支持高亮):

 <?xmlversion =1.0编码=UTF-8>
   <结构>
    <运行>
     < assemblyBindingxmlns =瓮:架构 - 微软COM:asm.v1>
       < dependentAssembly>
         < assemblyIdentityname =System.Runtime公钥=b03f5f7f11d50a3a文化=中性/>
         < bindingRedirectoldVersion =0.0.0.0-2.5.19.0NEWVERSION =2.5.19.0/>
       < / dependentAssembly>
       < dependentAssembly>
         < assemblyIdentityname =System.Threading.Tasks公钥=b03f5f7f11d50a3a文化=中性/>
         < bindingRedirectoldVersion =0.0.0.0-2.5.19.0NEWVERSION =2.5.19.0/>
       < / dependentAssembly>
      < / assemblyBinding>
    < /运行>
  < /结构>
 

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

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>

please help to sort out this problem, my application is ready and its now taking a bit long to just get it publish.

解决方案

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

Issue 6

Symptoms

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:

The primary reference "Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.5". To resolve this problem, either remove the reference "Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

The primary reference "Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.5". To resolve this problem, either remove the reference "Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

Solution

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 (StackOverflow does not support highlight):

 <?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>