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

China☆狼群 提交于 2020-01-12 19:32:01

问题


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

回答1:


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!




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/38734195/method-not-found-newtonsoft-json-jsonserializersettings-microsoft-aspnet-mvc-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!