-
Notifications
You must be signed in to change notification settings - Fork 54
Description
Problem
The Pathoschild.Http.FluentClient package depends on Microsoft.AspNet.WebApi.Client, which originates from the aspnet/AspNetWebStack repository. That is the legacy ASP.NET stack for MVC 5.x, Web API 2.x, and Web Pages 3.x.
This dependency is problematic for several reasons:
- End of support: ASP.NET Web API 2 reached end of support on July 1, 2019.
- No active development: No stable source release since October 2020 (5+ years).
System.Net.Http.Formattingand theMediaTypeFormatterabstraction were deliberately not brought forward to ASP.NET Core- Newtonsoft.Json: The package pulls in a transitive dependency on
Newtonsoft.Json. .NET moved toSystem.Text.Jsonas the platform default since .NET Core 3.0. System.Net.Http.Json(actively maintained in dotnet/runtime) is the official successor for HTTP content serialization.
Prior discussion
This has come up several times:
- Remove System.Net.Http.Formatting dependency #52 (2017) asked for removal, closed as wontfix
- Review supported frameworks #91 (2020) asked to modernize targets, declined
- Vulnerabilities Detected #120 (2022) related discussion
- System.Text.Json - json formatter #128 (2024) asked about System.Text.Json support
From #128: MediaTypeFormatter concept is a legacy part that the .NET team chose not to bring forward.
-
System.Net.Http.Jsondesign doc explains why they created a new assembly instead of extendingSystem.Net.Http.Formatting: "The existing assembly (which ships in Microsoft.AspNet.WebApi.Client package) provides the integration between HttpClient and JSON.NET. Mixing this with the new System.Text.Json would create a mess." -
.NET runtime code in
dotnet/runtime'sHttpMessageHandlerBuilder.csexplicitly avoids the old package: "This is similar to [System.Net.Http.Formatting/HttpClientFactory.cs] but we don't want to take that package as a dependency." -
David Fowler explained in dotnet/aspnetcore#3313 why the shared HTTP model that
MediaTypeFormatterdepended on was abandoned.
The modern approach is System.Net.Http.Json with simple extension methods (GetFromJsonAsync<T>(), etc.) no formatters, no content negotiation. A rewrite toward that model would be cleaner but would break the entire
public API surface (Formatters on IClient/IRequest/IResponse, IBodyBuilder.Model(), MediaTypeFormatterBase subclasses, etc.). That felt too disruptive for this change.
Proposed solution
Replace Microsoft.AspNet.WebApi.Client with lightweight, built-in abstractions:
- Define a new
IMediaTypeFormatterinterface (replacingSystem.Net.Http.Formatting.MediaTypeFormatter) - Provide
JsonMediaTypeFormatter(usingNewtonsoft.Json, preserving existing behavior) andXmlMediaTypeFormatter(usingDataContractSerializer) - Create a
MediaTypeFormatterCollection(same class name to minimize consumer breakage) - Update target frameworks to
netstandard2.0;net8.0
This removes the legacy dependency while keeping Newtonsoft.Json for backward compatibility (consumers can still configure JSON serialization the same way). A future version could add System.Text.Json support as an alternative formatter.
What could be added later (non-breaking):
- A
SystemTextJsonMediaTypeFormatterso consumers can choose between Newtonsoft.Json and System.Text.Json - Make System.Text.Json the default, with Newtonsoft.Json as opt-in
PR #134