json.net – 找不到方法:’Newtonsoft.Json.JsonSerializerSettings Microsoft.AspNet.Mvc.MvcJsonOptions.get_SerializerSettings()’

前端之家收集整理的这篇文章主要介绍了json.net – 找不到方法:’Newtonsoft.Json.JsonSerializerSettings Microsoft.AspNet.Mvc.MvcJsonOptions.get_SerializerSettings()’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
本地我的项目运行正常,但当我使用Web应用程序在Azure上部署时,我在启动时收到以下错误

MissingMethodException:找不到方法:’Newtonsoft.Json.JsonSerializerSettings Microsoft.AspNet.Mvc.Formatters.JsonOutputFormatter.get_SerializerSettings()’.
SmartAdmin.Startup.<> c.b__13_7(MvcOptions选项)

我试过这个:

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

还有这个:

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

        }).AddJsonOptions(options =>
        {
            options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
        });
是的,我刚刚工作了一整夜,并最终弄明白了.这是你需要做的:

确保安装:
-Microsoft.AspNet.Mvc.Formatters.Json版本“6.0.0-rc1-final”

– 将Netonsoft.Json恢复为“6.0.6”.

然后你可以保持这个:

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”

我在重新部署时遇到了一些麻烦,但最终还是有效.

祝好运!

原文链接:https://www.f2er.com/json/288438.html

猜你在找的Json相关文章