-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 Serialization issue when constructor has ReadOnlySpan<char> parameter #48827
Comments
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsWhen trying to serialize an object with a ReadOnlySpan parameter in the constructor, I get an Unhandled exception. of type System.TypeLoadException with the message: The generic type 'System.Text.Json.Serialization.Converters.SmallObjectWithParameterizedConstructorConverter`5' was used with an invalid instantiation in assembly 'System.Text.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. I'm using .Net 5 with "System.Text.Json" Version="5.0.1" This problem can be reproduced with this code: https://dotnetfiddle.net/edSoUp `using System; var typeWithString = new TypeWithString("foo"); var working = System.Text.Json.JsonSerializer.Serialize(typeWithString); Console.WriteLine(working); var json = System.Text.Json.JsonSerializer.Serialize(typewithSpan); Console.WriteLine(json); class TypeWithSpan
} class TypeWithString
}` The serialization of the type TypeWithString works as expected, the serialization of the type TypeWithSpan fails with :
|
Duplicate of #44327. Thanks for reporting the issue. |
When trying to serialize an object with a ReadOnlySpan parameter in the constructor, I get an Unhandled exception. of type System.TypeLoadException with the message: The generic type 'System.Text.Json.Serialization.Converters.SmallObjectWithParameterizedConstructorConverter`5' was used with an invalid instantiation in assembly 'System.Text.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
I'm using .Net 5 with "System.Text.Json" Version="5.0.1"
This problem can be reproduced with this code: https://dotnetfiddle.net/edSoUp
copied here for reference:
The serialization of the type TypeWithString works as expected, the serialization of the type TypeWithSpan fails with :
$(String[] args)Unhandled exception. System.TypeLoadException: The generic type 'System.Text.Json.Serialization.Converters.SmallObjectWithParameterizedConstructorConverter`5' was used with an invalid instantiation in assembly 'System.Text.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
at System.RuntimeTypeHandle.Instantiate(Type[] inst)
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.GetConverter(Type typeToConvert)
at System.Text.Json.JsonSerializerOptions.DetermineConverter(Type parentClassType, Type runtimePropertyType, MemberInfo memberInfo)
at System.Text.Json.JsonClassInfo.GetConverter(Type type, Type parentClassType, MemberInfo memberInfo, Type& runtimeType, JsonSerializerOptions options)
at System.Text.Json.JsonClassInfo..ctor(Type type, JsonSerializerOptions options)
at System.Text.Json.JsonSerializerOptions.GetOrAddClass(Type type)
at System.Text.Json.JsonSerializerOptions.GetOrAddClassForRootType(Type type)
at System.Text.Json.WriteStack.Initialize(Type type, JsonSerializerOptions options, Boolean supportContinuation)
at System.Text.Json.JsonSerializer.WriteCore[TValue](Utf8JsonWriter writer, TValue& value, Type inputType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Serialize[TValue](TValue& value, Type inputType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
at $.
The text was updated successfully, but these errors were encountered: