Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method not found: 'Newtonsoft.Json.JsonSerializerSettings Microsoft.AspNet.Mvc.MvcJsonOptions.get_SerializerSettings()'

Locally my project runs fine but when I deploy on Azure using a web app, I get the following error when it starts:

MissingMethodException: Method not found: 'Newtonsoft.Json.JsonSerializerSettings Microsoft.AspNet.Mvc.Formatters.JsonOutputFormatter.get_SerializerSettings()'. SmartAdmin.Startup.<>c.b__13_7(MvcOptions options)

I've tried this:

services.AddMvc(options =>
        {
                options.Filters.Add(new UserPreferencesLoaderAtrribute());
                var jsonFormatter = (JsonOutputFormatter)options.OutputFormatters.FirstOrDefault(f => f is JsonOutputFormatter);
                if (jsonFormatter != null)
                {
                jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            }
        });

And this:

services.AddMvc(options =>
        {
            options.Filters.Add(new UserPreferencesLoaderAtrribute());

        }).AddJsonOptions(options =>
        {
            options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
        });
like image 630
Jaime Bennett Avatar asked Aug 03 '16 04:08

Jaime Bennett


2 Answers

Yes, I just worked all night and did eventually figured it out. Here is what you need to do:

Make sure you install: -Microsoft.AspNet.Mvc.Formatters.Json version "6.0.0-rc1-final" and -Revert Netonsoft.Json to "6.0.6".

Then you can keep this:

services.AddMvc().AddJsonOptions(options =>
    {
        options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
    });

project.json:

"Microsoft.AspNet.Mvc.Formatters.Json": "6.0.0-rc1-final", "Newtonsoft.Json": "6.0.6"

I had a bunch of trouble redeploying too but eventually this worked.

Good luck!

like image 133
Jaime Bennett Avatar answered Sep 25 '22 01:09

Jaime Bennett


Just got off a call with Microsoft support as of yesterday (02 Aug 2016) Azure App Services now only support ASP.NET core, due to a breaking change:

A breaking change was released and anything other than ASP.NET core is not supported, so the only option is an upgrade. The breaking change is being rolled out to all (regions) eventually all your instances will fail.

Is ASP.NET 5, Core RC1, RC2 supported on Azure App Service? NO

https://blogs.msdn.microsoft.com/waws/2016/06/14/supporting-asp-net-5-core-rc1-on-azure-app-service/

Verify your app is running the latest version of ASP.NET Core and not RC1 or RC2.

We were affected (North Europe) and upgraded our app from RC2 and it worked first time.

like image 39
DalSoft Avatar answered Sep 23 '22 01:09

DalSoft