Skip to content

Failed deserialize with System.Text.Json in .NET 10 #168

Description

@arteny

Describe the bug

From your examples for System.Text.Json you are using DeserializeFromString method which is absent in .NET 10.
So it is failing to deserialize pure value for me now (not escaped):

JsonSerializer.Deserialize<T>("\"BetProExch\"")
Underlying type: System.String, Value = "BetProExch"
    Conversions: "[global::System.Text.Json.Serialization.JsonConverter(typeof(FancySourceSystemTextJsonConverter))]\r\n[global::System.ComponentModel.TypeConverter(typeof(FancySourceTypeConverter))]\r\n"
    UnderlyingType: "System.String"
    Value: "BetProExch"

JsonSerializer.Deserialize<T>("BetProExch")
'JsonSerializer.Deserialize<T>("BetProExch")' threw an exception of type 'System.Text.Json.JsonException'
    BytePositionInLine: 0
    Data: Count = 0
    HResult: -2146233088
    HelpLink: null
    InnerException: {"'B' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0."}
    LineNumber: 0
    Message: "'B' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0."
    Path: "$"
    Source: "System.Text.Json"
    StackTrace: "   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)\r\n   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, T& value, JsonSerializerOptions options, ReadStack& state)\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Deserialize(Utf8JsonReader& reader, ReadStack& state)\r\n   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo`1 jsonTypeInfo, Nullable`1 actualByteCount)\r\n   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo`1 jsonTypeInfo)\r\n   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)"
    TargetSite: {Void ReThrowWithPath(System.Text.Json.ReadStack ByRef, System.Text.Json.JsonReaderException)}

Can you provide any workaround how I can do it?

Steps to reproduce

JsonSerializer.Deserialize(anyCorrectMemberValue)

Expected behaviour

No exception

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions