Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 1.53 KB

README.md

File metadata and controls

27 lines (21 loc) · 1.53 KB

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