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