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.Formatting and the MediaTypeFormatter abstraction were deliberately not brought forward to ASP.NET Core
- Newtonsoft.Json: The package pulls in a transitive dependency on
Newtonsoft.Json. .NET moved to System.Text.Json as 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:
From #128: MediaTypeFormatter concept is a legacy part that the .NET team chose not to bring forward.
-
System.Net.Http.Json design doc explains why they created a new assembly instead of extending System.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's HttpMessageHandlerBuilder.cs explicitly 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 MediaTypeFormatter depended 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
IMediaTypeFormatter interface (replacing System.Net.Http.Formatting.MediaTypeFormatter)
- Provide
JsonMediaTypeFormatter (using Newtonsoft.Json, preserving existing behavior) and XmlMediaTypeFormatter (using DataContractSerializer)
- 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
SystemTextJsonMediaTypeFormatter so consumers can choose between Newtonsoft.Json and System.Text.Json
- Make System.Text.Json the default, with Newtonsoft.Json as opt-in
PR #134
Problem
The
Pathoschild.Http.FluentClientpackage depends onMicrosoft.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:
System.Net.Http.Formattingand theMediaTypeFormatterabstraction were deliberately not brought forward to ASP.NET CoreNewtonsoft.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:
From #128:
MediaTypeFormatterconcept 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.Jsonwith simple extension methods (GetFromJsonAsync<T>(), etc.) no formatters, no content negotiation. A rewrite toward that model would be cleaner but would break the entirepublic API surface (
FormattersonIClient/IRequest/IResponse,IBodyBuilder.Model(),MediaTypeFormatterBasesubclasses, etc.). That felt too disruptive for this change.Proposed solution
Replace
Microsoft.AspNet.WebApi.Clientwith lightweight, built-in abstractions:IMediaTypeFormatterinterface (replacingSystem.Net.Http.Formatting.MediaTypeFormatter)JsonMediaTypeFormatter(usingNewtonsoft.Json, preserving existing behavior) andXmlMediaTypeFormatter(usingDataContractSerializer)MediaTypeFormatterCollection(same class name to minimize consumer breakage)netstandard2.0;net8.0This 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):
SystemTextJsonMediaTypeFormatterso consumers can choose between Newtonsoft.Json and System.Text.JsonPR #134