Share via

ProblemDetails: Change in Instance Handling?

Freddie O'Connell 21 Reputation points
2021-08-18T14:28:09.837+00:00

I'm working on upgrading an MVC application from ASP.NET Core 2.1 to 3.1.

So far so good with actual behavior of the application, but an existing test condition is failing because an error payload used to contain "instance: null" but now no longer does.

Where we're using ProblemDetails, we weren't setting Instance explicitly, which is why it was null. After upgrading to ASP.NET Core 3.1, instance isn't there in the error payload.

I've looked through breaking changes and searched for anyone else having this issue. Is this a known issue?

I'm expecting we'll want to update our test conditions, but I'm also trying to figure out whether this was a known/breaking change documented anywhere in the ASP.NET Core upgrade pathway.

Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments

Answer accepted by question author
  1. Michael Taylor 61,206 Reputation points
    2021-08-18T15:50:07.947+00:00

    I don't think this has anything to do with ProblemDetails itself but the JSON serializer that is writing the data out. Prior to 3.1 ASP.NET used Newtonsoft.Json which was probably configured to write out default values for properties (aka null for unset reference types).

    However in 3.1 ASP.NET uses System.Text.Json by default. I haven't tested it myself but it is likely the default for the new serializer is to ignore default values and hence it won't write them out. You can refer to the migration guide here to see all the differences.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Freddie O'Connell 21 Reputation points
    2021-08-18T15:52:09.133+00:00

    Oh, wow. I hadn't even considered that side effect. That's probably exactly what's happening. Thanks for the tip!

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.