问题描述
我的项目在本地运行良好,但是当我使用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".
然后您可以保留以下内容:
Then you can keep this:
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()"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!