Unable to load System.Threading.Tasks.Extensions

倾然丶 夕夏残阳落幕 提交于 2021-01-21 06:37:21

问题


I have a web project build on .net framework 4.5.1. We are trying to added PostgreSQL support for the project. Using Nuget, I have installed 4.0.4 npgsql to the project. Under references, I see the following being added to the project.

  1. Npgsql - 4.0.4.0 - Runtime version v4.0.30319
  2. System.Threading.Tasks.Extensions - 4.2.0.0 - Runtime version v4.0.30319

When I tried run the project and connect and get the data from the database, I am getting the following error saying FileNotFoundException:

    System.TypeInitializationException
      HResult=0x80131534
      Message=The type initializer for 'com.rsol.RConfig' threw an exception.
      Source=RConfig
      StackTrace:
       at com.rsol.RConfig.getInstance() in C:\Workspaces\PS\RConfig\RConfig.cs:line 1113
       at RAdmin.Global.Application_Start(Object sender, EventArgs e) in C:\Workspaces\PS\RAdmin\Global.asax.cs:line 528

    Inner Exception 1:
    TypeInitializationException: The type initializer for 'com.rsol.Db.DbMgr' threw an exception.

    Inner Exception 2:
    FileNotFoundException: Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.

    Inner Exception 3:
    FileNotFoundException: 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 system cannot find the file specified.

System.Threading.Tasks.Extensions which is installed using Nuget is not getting loaded to the project. When I checked the properties of System.Threading.Tasks.Extensions reference, the dll file exists in the location. I have also tried installing System.Threading.Tasks.Extensions.dll file to assembly using gacutil. I am still getting the same error.

Please let me know if you need any additional information.

Any help is really appreciated.


回答1:


Update Nuget Package

https://www.nuget.org/packages/System.Threading.Tasks.Extensions/

will solve your problem




回答2:


In my case, I got the issue after upgrading to version 4.5.4 and tried @user2713341 answer. It didn't work but put me in the right direction.

My project had no bindings for this library, so I added the binding and it worked

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

and it worked.




回答3:


Update Nuget Package is not working for me.

What works? In app.config need to change

<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />

To

<bindingRedirect oldVersion="0.0.0.0-4.5.4" newVersion="4.5.4" />

for current version 4.7.2 should work.

Microsoft like ;)




回答4:


The response from @Keyjote was at the root of the solution for me, but rather than cherry-picking the assemblies, I was able to just reinstall. This seemed to automatically repair the app.config file.

Tools -> Nuget Packet Manager -> Packet Manager Console

Update-Package -reinstall -Project <your project name>

This way you don't need to mess with the syntax or have to figure out the PublicKeyToken values.

If you want to do it for the whole solution, you can omit the -Project <> parameter.




回答5:


problem lies in *.csproj file. having wrong reference for System.Threading.Tasks.Extensions.4.5.4 because this dll not loading. after referring correct framework version folder from lib its start working old Reference:

<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
    </Reference>
corrected one:

<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net472\System.Threading.Tasks.Extensions.dll</HintPath>
    </Reference>

please clean the nuget cache first, then run test case it will work




回答6:


Try to download the package and add reference to your project explicitly . should work , I just resolved it .



来源:https://stackoverflow.com/questions/59156537/unable-to-load-system-threading-tasks-extensions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!