1

I need to upgrade my WebApi2 project from 4.7.1 to 4.8 so I did the following:

  • Changed the Target Framework to 4.8 in the Properties tab
  • Changed 'targetFramework="net471"' to '"targetFramework=net48"' in the packages.config
  • Deleted bin and obj folders, and then did a nuget restore
  • Checked that all referenced files under References\Assemblies point to the SDK v4.8 folder
  • Rebuilt the solution

Then I changed the following in web.config:

<system.web>
  <compilation debug="true" targetFramework="4.8"/>
  <httpRuntime targetFramework="4.8"/>
</system.web>

However I get an exception when running the project:

Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

The corresponding section in web.config is:

  <dependentAssembly>
    <assemblyIdentity name="System.Net.Http" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
  </dependentAssembly>

The project is part of a larger solution and it references projects which target netstandard2.0. This is however not the problem, because everything was working when still using 4.7.1

Where / what else do I need to check / change to make get the project going using v4.8?

Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263
  • Remove that binding `dependentAssembly` element entirely, you should not need it. – Igor May 29 '20 at 14:09
  • 1
    See also [Could not load file or assembly “System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”](https://stackoverflow.com/a/47923538/1260204), the 2nd answer in order of votes. This is a great way to recreate all the binding redirects and then copy them to your `web.config` file. – Igor May 29 '20 at 14:12

1 Answers1

2

Following the steps as per @Igor 's comment reference the Could not load file or assembly “System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” solves the problem.

Definitely the best solution.

Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263