Description
AddExtendedHttpClientLogging(configurationSection) fails during startup when RequestHeadersDataClasses is configured from appsettings.json.
This appears to contradict the documented configuration path in the HTTP client logging docs:
https://learn.microsoft.com/en-us/dotnet/core/extensions/httpclient-logging?tabs=dotnet-cli#configure-from-appsettingsjson
The docs show this configuration:
{
"HttpClientLogging": {
"LogRequestStart": false,
"LogBody": false,
"BodySizeLimit": 32768,
"BodyReadTimeout": "00:00:01",
"RequestHeadersDataClasses": {
"User-Agent": "None",
"Content-Type": "None"
},
"ResponseHeadersDataClasses": {
"Content-Type": "None"
},
"RequestPathLoggingMode": "Formatted",
"RequestPathParameterRedactionMode": "Strict"
}
}
and this registration:
builder.Services.AddExtendedHttpClientLogging(
builder.Configuration.GetSection("HttpClientLogging"));
Reproduction Steps
- Create a minimal app using
Microsoft.Extensions.Http.Diagnostics 10.6.0.
- Register redaction services with
services.AddRedaction();.
- Register a named client with configuration-based HTTP client logging:
services.AddHttpClient("test")
.AddExtendedHttpClientLogging(configuration.GetSection("HttpClientLogging"));
- Use the documented
appsettings.json example from the docs.
- Build the service provider and create the client.
Minimal repro:
using System.Text;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using var stream = new MemoryStream(Encoding.UTF8.GetBytes("""
{
"HttpClientLogging": {
"LogRequestStart": false,
"LogBody": false,
"BodySizeLimit": 32768,
"BodyReadTimeout": "00:00:01",
"RequestHeadersDataClasses": {
"User-Agent": "None",
"Content-Type": "None"
},
"ResponseHeadersDataClasses": {
"Content-Type": "None"
},
"RequestPathLoggingMode": "Formatted",
"RequestPathParameterRedactionMode": "Strict"
}
}
"""));
var configuration = new ConfigurationBuilder()
.AddJsonStream(stream)
.Build();
var services = new ServiceCollection();
services.AddLogging();
services.AddRedaction();
services.AddHttpClient("test")
.AddExtendedHttpClientLogging(configuration.GetSection("HttpClientLogging"));
using var serviceProvider = services.BuildServiceProvider();
_ = serviceProvider.GetRequiredService<IHttpClientFactory>().CreateClient("test");
Expected behavior
The documented appsettings.json sample should bind successfully and the application should start.
RequestHeadersDataClasses and ResponseHeadersDataClasses should bind from configuration using values like "None" and "Unknown", as shown in the documentation.
Actual behavior
Startup fails while binding Microsoft.Extensions.Compliance.Classification.DataClassification.
Observed exception:
InvalidOperationException: Cannot create instance of type 'Microsoft.Extensions.Compliance.Classification.DataClassification' because parameter 'taxonomyName' has no matching config. Each parameter in the constructor that does not have a default value must have a corresponding config entry.
Additional isolated repro results:
- The docs-shaped sample fails as-is.
User-Agent: "None" alone fails.
Authorization: "Unknown" alone fails.
- Object-shaped attempts also fail, for example:
{
"HttpClientLogging": {
"RequestHeadersDataClasses": {
"User-Agent": {
"taxonomyName": "",
"value": "None"
}
}
}
}
with:
ArgumentException: Argument is whitespace (Parameter 'taxonomyName')
Regression?
Unknown. I have not yet tested earlier package versions.
Known Workarounds
Code-based configuration works:
services.AddHttpClient("test")
.AddExtendedHttpClientLogging(options =>
{
options.RequestHeadersDataClasses.Add("User-Agent", DataClassification.None);
options.RequestHeadersDataClasses.Add("Content-Type", DataClassification.None);
});
So the problem appears specific to the configuration-binding path.
Configuration
- Package:
Microsoft.Extensions.Http.Diagnostics 10.6.0
- SDK:
.NET SDK 10.0.201
- Host runtime:
.NET 10.0.8
- OS:
Windows 10.0.26200
- Architecture:
x64
- Reproduced in an isolated minimal repro
- Also reproduced in a larger real application using the same package version
Other information
This looks like one of two possibilities:
- the documented
appsettings.json shape is incorrect, or
DataClassification binding is currently broken for AddExtendedHttpClientLogging(configurationSection)
This does not appear to be specific to Authorization; it also reproduces with the docs sample using only User-Agent and Content-Type.
Description
AddExtendedHttpClientLogging(configurationSection)fails during startup whenRequestHeadersDataClassesis configured fromappsettings.json.This appears to contradict the documented configuration path in the HTTP client logging docs:
https://learn.microsoft.com/en-us/dotnet/core/extensions/httpclient-logging?tabs=dotnet-cli#configure-from-appsettingsjson
The docs show this configuration:
{ "HttpClientLogging": { "LogRequestStart": false, "LogBody": false, "BodySizeLimit": 32768, "BodyReadTimeout": "00:00:01", "RequestHeadersDataClasses": { "User-Agent": "None", "Content-Type": "None" }, "ResponseHeadersDataClasses": { "Content-Type": "None" }, "RequestPathLoggingMode": "Formatted", "RequestPathParameterRedactionMode": "Strict" } }and this registration:
Reproduction Steps
Microsoft.Extensions.Http.Diagnostics10.6.0.services.AddRedaction();.appsettings.jsonexample from the docs.Minimal repro:
Expected behavior
The documented
appsettings.jsonsample should bind successfully and the application should start.RequestHeadersDataClassesandResponseHeadersDataClassesshould bind from configuration using values like"None"and"Unknown", as shown in the documentation.Actual behavior
Startup fails while binding
Microsoft.Extensions.Compliance.Classification.DataClassification.Observed exception:
Additional isolated repro results:
User-Agent: "None"alone fails.Authorization: "Unknown"alone fails.{ "HttpClientLogging": { "RequestHeadersDataClasses": { "User-Agent": { "taxonomyName": "", "value": "None" } } } }with:
Regression?
Unknown. I have not yet tested earlier package versions.
Known Workarounds
Code-based configuration works:
So the problem appears specific to the configuration-binding path.
Configuration
Microsoft.Extensions.Http.Diagnostics10.6.0.NET SDK 10.0.201.NET 10.0.8Windows 10.0.26200x64Other information
This looks like one of two possibilities:
appsettings.jsonshape is incorrect, orDataClassificationbinding is currently broken forAddExtendedHttpClientLogging(configurationSection)This does not appear to be specific to
Authorization; it also reproduces with the docs sample using onlyUser-AgentandContent-Type.