C# CA2235:字段是可序列化但类型不可序列化的.NET标准的成员
我正在将一个项目从.NET framework(4.5)移植到.NET标准(2.0)。这段代码的框架版本似乎很满意,但标准部分给了我一个警告CA2235 如果C# CA2235:字段是可序列化但类型不可序列化的.NET标准的成员,c#,serialization,roslyn-code-analysis,C#,Serialization,Roslyn Code Analysis,我正在将一个项目从.NET framework(4.5)移植到.NET标准(2.0)。这段代码的框架版本似乎很满意,但标准部分给了我一个警告CA2235 如果 它是一个自动属性、带有支持字段的属性或只是一个 直场 是否为只读(即是否有setter) 我是否有0参数构造函数(有时与序列化问题相关) 因此,在下面的代码中: [Serializable] public class MyTestClass { // "MyString" below produces Warn
[Serializable]
public class MyTestClass
{
// "MyString" below produces Warning CA2235
// Field MyString is a member of type MyTestClass which is serializable but is of
// type string which is not serializable
public string MyString { get; set; }
// Field MyNullableInt is a member of type MyTestClass which is serializable but is of
// type int? which is not serializable
public int? MyNullableInt { get; set; }
//Both of the following seem to be OK
public int MyInt { get; set; }
public SomeEnum MyEnum { get; set; }
}
public enum SomeEnum
{
One,
Two,
Three
}
在我所做的搜索中,它出现了。我转到项目页面和“代码分析”选项卡,安装了analyzer包,其中添加了一个新的NuGet包
我原以为这就是我需要做的所有事情,但我想不是。我还缺少什么?(如果有关系,我使用的是VS2019)
在介绍我之前,让我们假设在我的情况下确实需要Serializable
属性。我更感兴趣的是,如果它被认为是固定的,为什么我仍然得到它