runtime: System.Net.Http does not behave as an OOB package when used with System.Net.Http.Formatting

This issue has been created to separate it from the conversation in issue dotnet/runtime#17770.

As explained there, when using System.Net.Http v4.0.0.0 as distributed by the .NET Framework 4.6.1, everything works correctly.

When updating the reference to the NuGet-distributed package for System.Net.Http v4.1.0.0 (here: https://www.nuget.org/packages/System.Net.Http/) the code fails at runtime whith the below exception:

[VerificationException: Method System.Net.Http.CloneableExtensions.Clone: type argument 'System.Net.Http.Headers.MediaTypeHeaderValue' violates the constraint of type parameter 'T'.]
System.Net.Http.Formatting.MediaTypeConstants.get_ApplicationJsonMediaType() +0
System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor() +79
System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters() +49
System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection routes)
...

When reverting to the out-of-the box v.4.0.0.0 version it works as expected without problems.

Therefore, version 4.1.0.0 is not an OOB package as it breaks the functionality of other packages that relate to this one.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 6
  • Comments: 15 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Couldn’t this be fixed in isolation of 1.1? This is affecting us and it seems like it’d affect a good chunk of people referencing NETStandard and System.Net.Http.Formatters together, not great to leave broken for months.

Just a heads up but this isn’t the only issue with cross compatibility. System.IdentyModel.Tokens.Jwt is also borked completely and breaks existing .NET 4.6 solutions that worked with the old version and you’re pushing this broken stuff on nuget.

I wasn’t aware that any type-subsetting was done with System.Net.Http.dll. Indeed if that exposes different surface area than the reference assembly in the package, and it has the same name, that’s a breaking change that needs to be fixed.

This isn’t about packaging, as i pointed out the contract is missing ICloneable. That needs to be added back, at least to the desktop implementation you’re providing out of band.

@danmosemsft and @stephentoub are adding this back to contract surface area but that won’t fix this case since that will have to be in a new NETStandard version that old desktop profiles won’t support.

The best fix here is for you to cross compile System.Net.Http as a desktop assembly, built against the desktop targeting pack, and make sure you implement ICloneable in that implementation.

This issue is definitely causing problems for users of packages that have added targetFramework usage of .NETStandard to their nuspec files. We make use of AutoMapper extensively in our project and and are running into this issue with the latest update.