NonSerialized on property

For those using JSON instead of XML you can use the [JsonIgnore] attribute on properties:

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

Available in both Newtonsoft.Json and System.Text.Json (.NET Core 3.0).


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;

Simple use:

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

Hopefully, it helps.


From C# 7.3 you may attach attributes to the backing field of auto-implemented properties.

Hence the following should work if you update your project's language to C# 7.3:

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