Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

c# - Unable to load System.Threading.Tasks.Extensions

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:WorkspacesPSRConfigRConfig.cs:line 1113
       at RAdmin.Global.Application_Start(Object sender, EventArgs e) in C:WorkspacesPSRAdminGlobal.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

Note that it should be 4.2.0.1 even though the version is 4.5.4.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...