0

I have been getting this error for a while now.

enter image description here

Oddly I only get this error when I publish the app to to Azure, locally it's fine.

I've tired changing the redirect to:

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

I've looked online and so fair no luck.

The app it's self is a Umbraco site using framework 4.7.2

Any help would be great!

UPDATE - I put System.Net.Http as a reference to my web project and set the copy local to true, this means the DLL was published but now I'm getting the error:

enter image description here

I've tried to add the following:

 <add assembly="System.Web.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

And I've also tried this:

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

Hope that helps

Scott L
  • 647
  • 3
  • 8
  • 21
  • Possible duplicate of [Strange issue with System.Net.Http 4.2.0.0 not found](https://stackoverflow.com/questions/47570912/strange-issue-with-system-net-http-4-2-0-0-not-found) – Eugene Sep 27 '18 at 20:48
  • I've been through that but it didn't help :(. I don't understand why this only happens on my Azure web app and not locally – Scott L Sep 27 '18 at 21:39

2 Answers2

1

The fix for this should be fairly easy: in your web.config find the compilation\assemblies section and add the System.Web.Http assembly there under System.Net.Http:

<add assembly="System.Web.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

Another thing that might help, if you get errors compiling your code, try referencing System.Web.Http version 4.2 and setting the build action to copy local.

For more details, you could refer to this article.

Joey Cai
  • 18,968
  • 1
  • 20
  • 30
  • Hi Joey, Thanks for the reply! I've tried adding in the assembly, do I also need the binding redirect? I have set copy local to true but it never goes into the bin folder so when I publish it's missing from the root of my azure app bin folder. Does that make sense? – Scott L Sep 28 '18 at 08:28
  • After setting copy local to true, have you rebuilt your project? When it appears in bin folder and then you publish it will work well. – Joey Cai Sep 28 '18 at 08:43
  • Hey, to give a bit more background, I have a class library that uses it and a web project that references that library. I added System.Net.Http as a reference to to web project and copy local to true, it now sends the DLL to the server when I publish, but I'm getting another error, I'll update the ticket so you can see – Scott L Sep 28 '18 at 09:02
  • Try delete that section from your web.config. Refer to this [issue](https://stackoverflow.com/questions/40207137/reference-assemblies-should-not-be-loaded-for-execution/42997402). – Joey Cai Sep 28 '18 at 09:32
  • I've just tried but I still get the same error, I can;t seem to add it via nuget, when I install the package and try to use HtttpClient() it says I need a ref so I put one in but it comes from my local one. – Scott L Sep 28 '18 at 09:56
  • I think I'm getting somewhere, It's now saying there's an error with Umbraco because it want's System.Net.Http version 4.0.0.0 – Scott L Sep 28 '18 at 10:25
0

I managed to fix this by removing all references to System.Http.Net, uninstalling it from NuGet, deleting the DLL form ( (c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib)

Then I installed it again via NuGet but the latest version and removed all the additional binding redirects from the web.config.

This then fixed the issue.

Thanks

Scott L
  • 647
  • 3
  • 8
  • 21