NonSerialized 属性忽略序列化报错'NonSerialized' is not valid on this declaration type

[XmlIgnore]
[NonSerialized]
public List<string> paramFiles { get; set; }

//I get the following error:

//Attribute 'NonSerialized' is not valid on this declaration type.
It is only valid on 'field' declarations.
 
 
Well... the first error says that you can't do that... from http://msdn.microsoft.com/en-us/library/system.nonserializedattribute.aspx
 [AttributeUsageAttribute(AttributeTargets.Field, Inherited = false)]
 [ComVisibleAttribute(true)]
 public sealed class NonSerializedAttribute : Attribute

I suggest using backing field

 public List<string> paramFiles { get { return list;}  set { list = value; } }
 [NonSerialized]
 private List<string> list;

参考:https://stackoverflow.com/questions/7693391/nonserialized-on-property

延伸:https://www.cnblogs.com/shy1766IT/p/5459707.html    Json序列化指定输出字段 忽略属性

原文地址:https://www.cnblogs.com/shy1766IT/p/11318863.html