找不到方法:'Newtonsoft.Json.JsonSerializerSettings Microsoft.AspNet.Mvc.MvcJsonOptions.get_SerializerSettings()' [英] Method not found: 'Newtonsoft.Json.JsonSerializerSettings Microsoft.AspNet.Mvc.MvcJsonOptions.get_SerializerSettings()'

查看:28
本文介绍了找不到方法:'Newtonsoft.Json.JsonSerializerSettings Microsoft.AspNet.Mvc.MvcJsonOptions.get_SerializerSettings()'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目在本地运行良好,但是当我使用 Web 应用程序在 Azure 上部署时,启动时出现以下错误:

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

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

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

我试过了:

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

推荐答案

是的,我只是工作了一夜,最终还是弄明白了.以下是您需要做的:

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

确保安装:-Microsoft.AspNet.Mvc.Formatters.Json 版本6.0.0-rc1-final"和- 将 Netonsoft.Json 恢复为6.0.6".

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

那么你可以保留这个:

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

project.json:

project.json:

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

"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.

祝你好运!

这篇关于找不到方法:'Newtonsoft.Json.JsonSerializerSettings Microsoft.AspNet.Mvc.MvcJsonOptions.get_SerializerSettings()'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆