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

标签 json.net azure-web-app-service

我的项目在本地运行良好,但当我使用 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();
    });

项目.json:

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

我在重新部署时也遇到了很多麻烦,但最终这成功了。

祝你好运!

关于json.net - 找不到方法 : 'Newtonsoft.Json.JsonSerializerSettings Microsoft.AspNet.Mvc.MvcJsonOptions.get_SerializerSettings()' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38734195/

相关文章:

c# - MVC 将自定义异常重新抛出为 JSON

spring - 在azure上部署maven web

azure - Azure 中应用程序服务的应用程序初始化不起作用

security - 如何使用 Azure 门户内的设置限制对应用服务的访问

Azure 站点扩展 xdt 转换顺序

c# - 如何在 C# 中从 json 模式创建默认的 json 对象

c# - 是否有一个库可以在 Windows Mobile 上用 C# 读取 JSON?

c# - 在 JSON.NET 中将整数序列化为十六进制

c# - 如何反序列化 JSON 数据?

asp.net-mvc - AADSTS70001 : Application with identifier 'guid' was not found in the directory