XmlSerializerInputFormatter已过时-ASP.NET Core 2.1 [英] XmlSerializerInputFormatter is obsolete - ASP.NET Core 2.1
问题描述
我正在使用以下代码接受在我的Core API应用中序列化的XML.
I am using the following to accept XML serialized in my Core API App.
services.AddMvc(options =>
{
// allow xml format for input
options.InputFormatters.Add(new XmlSerializerInputFormatter());
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
更新到ASP.NET Core 2.1之后,我收到以下警告:
After updating to ASP.NET Core 2.1 I receive the following warning:
'XmlSerializerInputFormatter.XmlSerializerInputFormatter()'已过时:'此构造函数已过时,将在以后的版本中删除.'
'XmlSerializerInputFormatter.XmlSerializerInputFormatter()' is obsolete: 'This constructor is obsolete and will be removed in a future version.'
处理此问题的新方法是什么?
What is the new way to handle this?
推荐答案
According to the source code, there's a constructor that has not been marked as Obsolete
:
public XmlSerializerInputFormatter(MvcOptions options)
此构造函数采用MvcOptions
的实例,因此您可以通过现有的options
参数:
This constructor takes an instance of MvcOptions
, so you can pass through your existing options
argument:
services.AddMvc(options =>
{
// allow xml format for input
options.InputFormatters.Add(new XmlSerializerInputFormatter(options));
}) ...
从ASP.NET Core 3.0开始,此构造函数是唯一可用的构造函数.那些标记为过时的标记现在已被删除.
As of ASP.NET Core 3.0, this constructor is the only one available. Those that were marked obsolete have now been removed.
这篇关于XmlSerializerInputFormatter已过时-ASP.NET Core 2.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!