Skip to content

Illustrates exceptions when returning JsonResult with JsonSerializerSettings from a .NET Core 3.1 azure function v3 application

Notifications You must be signed in to change notification settings

HMoen/FunctionApp-JsonResult-Error

Repository files navigation

Description:

Illustrates exceptions thrown when returning JsonResult containing serializer settings in a .NET Core 3.1 azure function v3 application based on scenarios below.

Problem:

Returning JsonResult containing JsonSerializerSettings passed to the ctor from an azure function with .NET Core 3.1 runtime throws an unhandled exception at the host level.

Exceptions thrown based on scenario:

  1. Vanilla AF: System.Private.CoreLib: Exception while executing function: FunctionTestJsonOutput. FunctionAppJsonError: Method not found: 'Void Microsoft.AspNetCore.Mvc.JsonResult..ctor(System.Object, Newtonsoft.Json.JsonSerializerSettings)'.
  2. After adding Nuget Microsoft.AspNetCore.Mvc.NewtonsoftJson: Microsoft.AspNetCore.Mvc.NewtonsoftJson: Property 'JsonResult.SerializerSettings' must be an instance of type 'Newtonsoft.Json.JsonSerializerSettings'.
  3. After using DI with IFunctionsHostBuilder.Services.AddControllers().AddNewtonsoftJson(): Microsoft.AspNetCore.Authentication.Core: No authentication handlers are registered. Did you forget to call AddAuthentication().Add[SomeAuthHandler]("WebJobsAuthLevel",...)?.

Workaround:

  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

Discussion:

Azure/azure-functions-host#5376

Solution:

  • Add Nuget Microsoft.AspNetCore.Mvc.NewtonsoftJson to your poject

About

Illustrates exceptions when returning JsonResult with JsonSerializerSettings from a .NET Core 3.1 azure function v3 application

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages