- 
                Notifications
    You must be signed in to change notification settings 
- Fork 10.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Since we upgraded to .NET 10, the following code throws exception:
System.Text.Json.JsonSerializerOptions serializerOptions = new System.Text.Json.JsonSerializerOptions
{
    PropertyNameCaseInsensitive = true,
    DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault
};
var singleTestOption = new Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerOptions();
string optionAsString = System.Text.Json.JsonSerializer.Serialize(singleTestOption, serializerOptions); // <-- throws exception
In .NET 9 the above code did NOT throw exception and successfully serialized.
Expected Behavior
No response
Steps To Reproduce
No response
Exceptions (if any)
System.NotSupportedException: Serialization and deserialization of 'System.Func2[[Microsoft.AspNetCore.Authentication.JwtBearer.AuthenticationFailedContext, Microsoft.AspNetCore.Authentication.JwtBearer, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Threading.Tasks.Task, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' instances is not supported. The unsupported member type is located on type 'System.Func2[Microsoft.AspNetCore.Authentication.JwtBearer.AuthenticationFailedContext,System.Threading.Tasks.Task]'. Path: $.Events.OnAuthenticationFailed.
---> System.NotSupportedException: Serialization and deserialization of 'System.Func2[[Microsoft.AspNetCore.Authentication.JwtBearer.AuthenticationFailedContext, Microsoft.AspNetCore.Authentication.JwtBearer, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Threading.Tasks.Task, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' instances is not supported. at System.Text.Json.Serialization.Converters.UnsupportedTypeConverter1.Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
at System.Text.Json.Serialization.JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.JsonConverter1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
--- End of inner exception stack trace ---
at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& state, Exception innerException)
at System.Text.Json.Serialization.JsonConverter1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.Metadata.JsonTypeInfo1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed)
at System.Text.Json.JsonSerializer.WriteString[TValue](TValue& value, JsonTypeInfo`1 jsonTypeInfo)
at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
at Test.Service.Worker.ExecuteAsync(CancellationToken stoppingToken)
.NET Version
10.0.100-rc.2.25502.107
Anything else?
No response