Illustrates exceptions thrown when returning JsonResult containing serializer settings in a .NET Core 3.1 azure function v3 application based on scenarios below.
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.
- 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)'.
- After adding Nuget Microsoft.AspNetCore.Mvc.NewtonsoftJson: Microsoft.AspNetCore.Mvc.NewtonsoftJson: Property 'JsonResult.SerializerSettings' must be an instance of type 'Newtonsoft.Json.JsonSerializerSettings'.
- 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",...)?.
- Add Nuget Microsoft.AspNetCore.Mvc.NewtonsoftJson to your poject
- Add the following in local.settings.json and Azure App Settings: "FUNCTIONS_V2_COMPATIBILITY_MODE": true
Azure/azure-functions-host#5376
- Add Nuget Microsoft.AspNetCore.Mvc.NewtonsoftJson to your poject