Jaime Bennett
Jaime Bennett

Reputation: 151

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();
        });

Upvotes: 8

Views: 5717

Answers (3)

Jouni Heikniemi
Jouni Heikniemi

Reputation: 2335

We also saw this in production, contacted the team and got this out: https://social.msdn.microsoft.com/Forums/en-US/f0a6bbaf-498a-4c1f-b869-6779ee18e04e/app-service-applications-may-experience-methodnotfound-exceptions-due-to-incorrect-newtonsoft-json?forum=windowsazurewebsitespreview

It appears that a fix for App Service is on its way as well. Meanwhile, the linked post contains pretty much the same instructions as the other answers here.

Upvotes: 0

DalSoft
DalSoft

Reputation: 11088

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.

Upvotes: 1

Jaime Bennett
Jaime Bennett

Reputation: 151

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!

Upvotes: 7

Related Questions