1
votes

I had a project .net core 2.2 and I switch to 3.1 after that when call a api I have Exception

public override void OnActionExecuted(Microsoft.AspNetCore.Mvc.Filters.ActionExecutedContext context)
{
    var response = context.Result as ObjectResult;

    if (response?.Value == null)
        return;
}

context.Result is always null and shows me below exception:

"Could not load type 'Microsoft.AspNetCore.Mvc.Formatters.JsonSerializerSettingsProvider' from assembly 'Microsoft.AspNetCore.Mvc.Formatters.Json, Version=3.1.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.":"Microsoft.AspNetCore.Mvc.Formatters.JsonSerializerSettingsProvider"

Please guide me.

1

1 Answers

1
votes

Try to restore npm packages, and make sure you have installed the "Microsoft.AspNetCore.Mvc.Formatters.Json" package.

Besides, please check the Migrate from ASP.NET Core 2.2 to 3.0 document:

As part of the work to improve the ASP.NET Core shared framework, Newtonsoft.Json (Json.NET) has been removed from the ASP.NET Core shared framework. the default JSON serializer for ASP.NET Core is now System.Text.Json

So, you could try to use the System.Text.Json Or using the Newtonsoft.Json in an ASP.NET Core.

More detail information, please check the following links:

Newtonsoft.Json (Json.NET) support

Change the JSON serialization settings of a single ASP.NET Core controller