MSDN Documentation

SerializationTransient Attribute

Indicates that a field should not be serialized. This attribute can only be applied to fields.

Class

System.Attribute

Namespace: System.Runtime.Serialization
Assembly: mscorlib (in mscorlib.dll)

Syntax

[System.AttributeUsageAttribute(System.AttributeTargets.Field, Inherited=false)]
public sealed class SerializationTransientAttribute : Attribute

Attribute Usage

This attribute can be applied to fields only.

[SerializationTransient]

Remarks

The SerializationTransientAttribute attribute is used to prevent a field from being serialized by the common language runtime (CLR) serialization. This is useful when you have fields that contain sensitive information, temporary data, or data that should not be persisted.

When the CLR performs serialization, it inspects each field of an object. If a field is marked with the SerializationTransientAttribute, that field will be skipped and its value will not be included in the serialized output.

This attribute is particularly useful in conjunction with other serialization mechanisms, such as BinaryFormatter or XmlSerializer, where you might want fine-grained control over what gets serialized.

Note that this attribute only affects CLR serialization. Other serialization methods or custom serialization logic might not respect this attribute.

Requirements

.NET Framework supported versions
Supported in: 4.5, 4.5.1, 4.5.2, 4.5.3, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 3.5, 3.0, 2.0
Target platform
Windows, Web, WPF, Windows Forms, .NET Core
Header file
mscorlib.dll
NuGet package
None

See Also