When I write code like this
[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.
If I write
[field: NonSerialized]
I get the following warning
'field' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'property'. All attributes in this block will be ignored.
If I write
[property: NonSerialized]
I get the following error (again):
Attribute 'NonSerialized' is not valid on this declaration type. It is only valid on 'field' declarations.
How can I use [NonSerialized]
on a property?
You can prevent member variables from being serialized by marking them with the NonSerialized attribute as follows. If possible, make an object that could contain security-sensitive data nonserializable. If the object must be serialized, apply the NonSerialized attribute to specific fields that store sensitive data.
When using the BinaryFormatter or SoapFormatter classes to serialize an object, use the NonSerializedAttribute attribute to prevent a field from being serialized. For example, you can use this attribute to prevent the serialization of sensitive data.
Non-serialized means more than just an item that does not have a serial number, if you are receiving items without a serial number you should review the differences below and decide if you want to use serialized or non-serialized.
Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.
Simple use:
[XmlIgnore] [ScriptIgnore] public List<string> paramFiles { get; set; }
Hopefully, it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With