question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serialization error after upgrade to v5.0.0

See original GitHub issue

So I have this code in my Startup.cs:

services.AddProblemDetails(setup =>
 {
    setup.IncludeExceptionDetails = (c, e) => environment.IsDevelopment(); // -> before updating to v5, I had _ =>environment.IsDevelopment(); here
    setup.Map<DomainValidationException>(
        (context, ex) => new ValidationProblemDetails(ex.Errors).Build(context));
});

Now my json looks like this, which blows up in deserialisation because of the duplicate “errors” field:

  {
    "errors": {
        "exportPath": [
            "..."
        ]
    },
    "type": "https://httpstatuses.com/400",
    "title": "One or more validation errors occurred.",
    "status": 400,
    "detail": "Please refer to the errors property for additional details.",
    "instance": "/api/externalApplications/4240656a-a669-4fba-842a-abbb00dca30f",
    "errors": [
        {
            "message": "Domain validation failed. See Errors for details.",
[...]

Before the update (v4.5), the json was just

{
    "errors": {
        "exportPath": [
            "..."
        ]
    },
    "type": "https://httpstatuses.com/400",
    "title": "One or more validation errors occurred.",
    "status": 400,
    "detail": "Please refer to the errors property for additional details.",
    "instance": "/api/externalApplications/7a52e19a-ce16-480c-9999-abbb00e0c8c7"
}

Fixed it by doing this in my startup, but I don’t know if this is what you intended:

setup.IncludeExceptionDetails = (c, e) =>
{
     return e switch
     {
         DomainValidationException _ => false,
         _ => environment.IsDevelopment()
    };
};

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
angularsencommented, Jul 20, 2021

@khellang I was just hit by this too, 1 year later on 5.4 after upgrading from 4.5. I second the ☝️ suggestion of changing the default name to exceptionDetails.

Out of the box, we run into problems with Refit no longer recognizing the validation error and throws Refit.ApiException instead of Refit.ValidationApiException, which loses the ProblemDetails it tries to deserialize for 400 Bad Request. Changing the property name fixed this.

Update: Created PR #139 .

1reaction
khellangcommented, May 14, 2020

Just pushed v5.1.0 to NuGet. It has an additional ExceptionDetailsPropertyName option that should let you use a different name 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrade to v5 fails using upgrade script · Issue #8553
The upgrade to v5 fails using the php upgrade.php script. ... Steps to reproduce the behavior: Attempt upgrade using php upgrade.php from v4.9.5 ......
Read more >
My old program doesn't work after update 2022-KB5012159
When I update 2022-KB5012159.There has been an error.Not find assmbly ”System.Runtime.Serialization, Version=3.0.0.0,Culture=neutral.
Read more >
Net 5 Api System.NotSupportedException: Serialization ...
I can see the controller action gets executed so deserialization works fine on the way in. It fails when writing response.
Read more >
Errors in sync projects after upgrade from 8.2.1 to 9.1 - Forum
Hi,. We're performing a series of tests before upgrading our systems to 9.1. The process ends up flawlessly but the DPR migration processes ......
Read more >
Patch Notes | Odin Inspector for Unity
Fixed a bug that would happen in newer versions of Unity, where clicking on an issue in the odin validator window would cause...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found