<PackageReference Include="System.Text.Json" Version="6.0.0-preview.5.21301.5" />

JsonException

public class JsonException : Exception
Defines a custom exception object that is thrown when invalid JSON text is encountered, when the defined maximum depth is passed, or the JSON text is not compatible with the type of a property on an object.
using System.Runtime.CompilerServices; using System.Runtime.Serialization; namespace System.Text.Json { [Serializable] [System.Runtime.CompilerServices.NullableContext(2)] [System.Runtime.CompilerServices.Nullable(0)] public class JsonException : Exception { internal string _message; internal bool AppendPathInformation { get; set; } public long? LineNumber { get; set; } public long? BytePositionInLine { get; set; } public string Path { get; set; } [System.Runtime.CompilerServices.Nullable(1)] public override string Message { [System.Runtime.CompilerServices.NullableContext(1)] get { return _message ?? base.Message; } } public JsonException(string message, string path, long? lineNumber, long? bytePositionInLine, Exception innerException) : base(message, innerException) { _message = message; LineNumber = lineNumber; BytePositionInLine = bytePositionInLine; Path = path; } public JsonException(string message, string path, long? lineNumber, long? bytePositionInLine) : base(message) { _message = message; LineNumber = lineNumber; BytePositionInLine = bytePositionInLine; Path = path; } public JsonException(string message, Exception innerException) : base(message, innerException) { _message = message; } public JsonException(string message) : base(message) { _message = message; } public JsonException() { } [System.Runtime.CompilerServices.NullableContext(1)] protected JsonException(SerializationInfo info, StreamingContext context) : base(info, context) { LineNumber = (long?)info.GetValue("LineNumber", typeof(long?)); BytePositionInLine = (long?)info.GetValue("BytePositionInLine", typeof(long?)); Path = info.GetString("Path"); SetMessage(info.GetString("ActualMessage")); } [System.Runtime.CompilerServices.NullableContext(1)] public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); info.AddValue("LineNumber", LineNumber, typeof(long?)); info.AddValue("BytePositionInLine", BytePositionInLine, typeof(long?)); info.AddValue("Path", Path, typeof(string)); info.AddValue("ActualMessage", Message, typeof(string)); } internal void SetMessage(string message) { _message = message; } } }