-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Description
I am receiving an ArgumentNullException from JsonSerializer.Serialize<T>(Utf8JsonWriter, T value, JsonSerializerOptions options) that appears to be the result of a faulty null-check-override within JsonTypeInfo.
runtime/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfo.cs
Line 526 in 804a933
| Name = reflectionInfo.Name!, |
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.OrdinalIgnoreCaseComparer.GetHashCode(String obj)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ParameterLookupKey.GetHashCode()
at System.Collections.Generic.Dictionary`2.FindValue(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.InitializeConstructorParameters(ConstructorInfo constructorInfo)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo..ctor(Type type, JsonConverter converter, Type runtimeType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializerOptions.<RootBuiltInConvertersAndTypeInfoCreator>g__CreateJsonTypeInfo|107_0(Type type, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.GetTypeInfo(Type runtimeType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Serialize[TValue](Utf8JsonWriter writer, TValue& value, Type runtimeType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Serialize[TValue](Utf8JsonWriter writer, TValue value, JsonSerializerOptions options)
at Modix.Host.EntryPoint.EndpointWriteOnlyJsonConverter.Write(Utf8JsonWriter writer, Endpoint value, JsonSerializerOptions options) in D:\Projects\JakenVeina\MODiX\MODiX.Host\EntryPoint.cs:line 90
The null value in question is coming from System.Reflection.ParameterInfo.Name, retrieved from the constructor of System.Runtime.CompilerServices.NullableContextAttribute.
The NullableContextAttribute instance is coming from Microsoft.AspNetCore.Http.Endpoint which is being passed to Microsoft.Extensions.Logging.ILogger.Log calls as TState state.
NullableContextAttribute is an internal and compiler-generated type, so it's been proving difficult to implement a workaround where I just skip or customize serialization of the type. It also strikes me as a slight design defect that all this work is being done to analyze this type for deserialization, when I am only attempting to serialize it, and have no intention of ever deserializing it.
Configuration
.NET SDK 6.0.100-preview.7.21379.14
System.Text.Json 6.0.0-preview.7.21377.19