Skip to content

JsonResult with JsonSerializerSettings throws exception in .NET Core 3.1 / Azure Functions v3 #5376

Closed
@HMoen

Description

@HMoen

Issue

AF returning JsonResult with JsonSerializerSettings (StringEnumConverter, NullValueHandling = NullValueHandling.Ignore) instance passed through its constructor throws an exception.

Investigative information

  • Function App version: 3.0
  • Function App runtime: .Net Core 3.1

Repro steps

https://github.com/HMoen/FunctionApp-JsonResult-Error/

Expected behavior

{
    "Status": "Pending",
    "WithValue": "Has value"
}

Actual behavior

Throws exception: Microsoft.AspNetCore.Mvc.NewtonsoftJson: Property 'JsonResult.SerializerSettings' must be an instance of type 'Newtonsoft.Json.JsonSerializerSettings'
Removing the passed JsonSerializerSettings in JsonResult:

{
    "status": 0,
    "withValue": "Has value",
    "nullValue": null
}

Known workarounds

  1. Add Nuget Microsoft.AspNetCore.Mvc.NewtonsoftJson to your poject
  2. Add the following in local.settings.json and Azure App Settings: "FUNCTIONS_V2_COMPATIBILITY_MODE": true

Related information

#5358 (comment)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions