-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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.JsonException: Reference '{$id}' not found. #45639
Comments
Similar issues have been reported in the past, check out this comment, maybe it solves your problem: #45325 (comment) |
Some more context: public class Number
{
public int Value { get; set; }
public string Name { get; set; }
public IList<Category> Categories { get; set; }
}
public class Category
{
public string Name { get; set; }
public IList<Number> Numbers { get; set; }
} |
@BrunoBlanes - based on the input JSON, it looks like you need to specify either var response = await Http.GetFromJsonAsync<IList<Number>>("Number", new JsonSerializerOptions
{
ReferenceHandler = ReferenceHandler.Preserve,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase // this is needed
}); Let us know if you still face issues here. |
I forgot about naming policies... I went with |
@layomia, @Jozkee - consider this as another ref count for better exception and error messaging to help debugging mentioned here as well. If it is easy to do with minimal code changes, great. Otherwise, maybe update the exception message string being thrown when preserve is on to include potential causes for such an error generally so at least folks have a hint of what things to look out for. |
Description
Exception is thrown when trying to deserialize a Json object serialized using
ReferenceHandler.Preserve
on Blazor WebAssembly:Server
Json
Client
Exception stack
Remarks
HttpClient
extension method and the usualJsonSerializer
approach with the same results.The text was updated successfully, but these errors were encountered: