12
我在ASP.NET webapi项目中使用了Swashbuckle 5以及所有默认设置。它序列化我的方法的输出,以显示答案的模式。我得到的文件,看起来像这样:k__BackingField在C#中删除(通过Swashbuckle/Swagger看到)
Response Class (Status 200)
Model Model Schema
[
{
"<Key>k__BackingField": "string",
"<Value>k__BackingField": "string",
"<Id>k__BackingField": 0
}
]
这是由下面的C#代码生成
/// <summary>
/// Fetches all system configuration items
/// </summary>
/// <returns>List of <see cref="SystemConfigurationDto" /> items</returns>
public IList<SystemConfigurationDto> GetAllSystemConfigurationItems()
{
var result = CommandProcessor.ProcessCommand(new SystemConfigurationQueryCommand()) as SystemConfigurationQueryCommandResponse;
return result.Results.ToList();
}
其中result.Results基本上是对象的标准列表,每个都包含这些键/值/ ID领域。我已经在这里读了https://conficient.wordpress.com/2014/05/22/getting-rid-of-k__backingfield-in-serialization/ [serializable]属性可能会影响这个,但如果可能的话,我不愿意去掉那个属性。是否有任何配方来调整这个序列化神器?
这让我一整个早上。今天早上我突然遇到它升级了一些NuGet软件包。该解决方案之前几个月工作得很好。 '[Serializable]'属性不是,并且从未在任何地方使用过。添加此代码段解决了它。非常感谢你,先生! – ceej
谢谢,也为我工作 – spooti