-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ArgumentNullException in System.Text.Json.Serialization.Metadata.JsonTypeInfo #58690
Comments
Hi @JakenVeina, would it be possible to provide a minimal app that reproduces the issue? Thanks. |
It looks like a "minimal" reproduction might not be possible. I have replicated the scenario in a simple console program, using the same runtime and package versions, and the exception does not occur. I.E... JsonSerializer.Serialize(writer, value, options); ...where I will attempt to clone my full application and trim as much out of it as possible, without affecting the exception that throws. |
Here we go: https://github.com/JakenVeina/DotnetRuntimeIssue58690 I identified the issue with reproducing it locally: I was inadvertently calling |
I can reproduce. Minimal reproduction: using System;
using System.Reflection;
using System.Text.Json;
Type type = Assembly.GetExecutingAssembly().GetType("System.Runtime.CompilerServices.NullableContextAttribute")!;
object value = Activator.CreateInstance(type, (byte)0)!;
JsonSerializer.Serialize(value);
// Force generation of a NullableContextAttribute in this assembly
static string? MethodWithNullableAnnotations() => throw new NotImplementedException(); Throws
I did not deduce the root cause -- for some reason attempting to replicate the implementation of This seems like a very niche use case. Moving to 7.0.0. |
Moving to Future, as we won't have time to work on this in the .NET 7 timeframe. |
Root cause appears to be IL #73188 (comment) containing parameters with stripped names. Given that the linker can trim parameter names to save size we might want to add detection logic for |
Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer, @joperezr Issue DetailsDescriptionI am receiving an runtime/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfo.cs Line 526 in 804a933
The The
Configuration.NET SDK 6.0.100-preview.7.21379.14
|
* Add runtime detection for constructor parameters with missing names. Fix dotnet#58690. * Extend NotSupportedTypeConverter to MemberInfo types from System.Type types. Contributes to dotnet#58947.
Description
I am receiving an
ArgumentNullException
fromJsonSerializer.Serialize<T>(Utf8JsonWriter, T value, JsonSerializerOptions options)
that appears to be the result of a faulty null-check-override withinJsonTypeInfo
.runtime/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfo.cs
Line 526 in 804a933
The
null
value in question is coming fromSystem.Reflection.ParameterInfo.Name
, retrieved from the constructor ofSystem.Runtime.CompilerServices.NullableContextAttribute
.The
NullableContextAttribute
instance is coming fromMicrosoft.AspNetCore.Http.Endpoint
which is being passed toMicrosoft.Extensions.Logging.ILogger.Log
calls asTState state
.NullableContextAttribute
is aninternal
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
The text was updated successfully, but these errors were encountered: