将我的 win-forms-project 升级到 .NET 9 后,我的用户控件的属性现在出现以下错误:
WFO1000: Property 'property' does not configure the code serialization for its property content.
然后我阅读了微软对该问题的解释: https://learn.microsoft.com/en-us/dotnet/core/compatibility/windows-forms/9.0/security-analyzers
现在我了解了安全问题,但我仍然不知道如何解决它。 我不想压制此消息,我想正确处理此序列化问题。
微软在那篇文章中建议:
Review the properties flagged by the analyzer and configure appropriate serialization settings as needed.
现在我想知道:我到底该怎么做?
通过声明适当的属性。例如:
如果您不想保存(即序列化)该值:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override Color BackColor { get => base.BackColor; set => base.BackColor = value; }
或
如果您想保存(即序列化)该值:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override Color BackColor { get => base.BackColor; set => base.BackColor = value; }