-
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
[System.Text.Json] Regression: [JsonIgnore] Attribute not Applied to Ref Returns #59936
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json Issue DetailsDescriptionFound a regression in Regression was introduced in As I'm not familiar with how dotnet is exactly built, I do not know how to pinpoint the sdk build number to the exact commit causing the issue however; but the build version should hopefully be useful. Minimal Reproduction: using System.Diagnostics;
using System.Text.Json;
using System.Text.Json.Serialization;
var sampleText = new TypeWithRefString();
var json = JsonSerializer.Serialize(sampleText); // Exception Here
var deserialized = JsonSerializer.Deserialize<TypeWithRefString>(json); // And Here
internal class TypeWithRefString
{
[JsonIgnore]
public ref string NameRef => ref Name;
public string Name = "How many Richard Landers does it take to write a blog entry? Just one, you rock!";
} Debug in your own desired way. ConfigurationN/A Regression?Yes, this use case worked with any version of System.Text.Json <= Other informationException: System.ArgumentException: 'The type 'System.String&' may not be used as a type argument.'
at System.RuntimeType.ThrowIfTypeNeverValidGenericArgument(RuntimeType type)
at System.RuntimeType.SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters)
at System.RuntimeType.MakeGenericType(Type[] instantiation)
at System.Text.Json.Serialization.Converters.ObjectConverterFactory.CreateConverter(Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.Serialization.JsonConverterFactory.GetConverterInternal(Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.JsonSerializerOptions.GetConverterInternal(Type typeToConvert)
at System.Text.Json.JsonSerializerOptions.DetermineConverter(Type parentClassType, Type runtimePropertyType, MemberInfo memberInfo)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.GetConverter(Type type, Type parentClassType, MemberInfo memberInfo, Type& runtimeType, JsonSerializerOptions options)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.AddProperty(MemberInfo memberInfo, Type memberType, Type parentClassType, Boolean isVirtual, Nullable`1 parentTypeNumberHandling, JsonSerializerOptions options)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.CacheMember(Type declaringType, Type memberType, MemberInfo memberInfo, Boolean isVirtual, Nullable`1 typeNumberHandling, Boolean& propertyOrderSpecified, Dictionary`2& ignoredMembers)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo..ctor(Type type, JsonConverter converter, Type runtimeType, JsonSerializerOptions options)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo..ctor(Type type, JsonSerializerOptions options)
at System.Text.Json.JsonSerializerOptions.<RootBuiltInConvertersAndTypeInfoCreator>g__CreateJsonTypeInfo|107_0(Type type, JsonSerializerOptions options)
at System.Text.Json.JsonSerializerOptions.GetClassFromContextOrCreate(Type type)
at System.Text.Json.JsonSerializerOptions.GetOrAddClass(Type type)
at System.Text.Json.JsonSerializerOptions.GetOrAddClassForRootType(Type type)
at System.Text.Json.JsonSerializer.GetTypeInfo(Type runtimeType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Write[TValue](TValue& value, Type runtimeType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
at Program.<Main>$(String[] args) in C:\Users\sewer\Desktop\Projects\SystemTextJsonBug\SystemTextJsonBug\SystemTextJsonBug\Program.cs:line 12
|
Can repro -- I believe this is the same regression as the one reported in #58469 (comment). We made the call earlier not to revert the change, but it seems to me that this particular issue makes a more compelling case /cc @layomia Related to #59364. |
Ha! I'll be writing the RC2 post this week. |
Re-opening so we can consider porting the fix to .NET 6.0. |
Fixed by #60299 |
Description
Found a regression in
System.Text.Json
where using properties withref returns
cannot be ignored for serialization, leading to an unavoidable exception.Regression was introduced in
System.Text.Json 6.0.0-rc.1.21406.5
, going by the available packages in thedotnet6
NuGet repo. This package was pushed on Friday, August 6th, 2021.As I'm not familiar with how dotnet is exactly built, I do not know how to pinpoint the sdk build number to the exact commit causing the issue however; but the build version should hopefully be useful.
Minimal Reproduction:
Debug in your own desired way.
This snippet can be pasted and ran over a blank .NET 6 console app.
Configuration
N/A
Regression?
Yes, this use case worked with any version of System.Text.Json <=
6.0.0-rc.1.21406.4
;Other information
Exception:
The text was updated successfully, but these errors were encountered: