BinaryFormatter.Serialize(Stream, Object) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Caution
BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.
Serializes the object, or graph of objects with the specified top (root), to the given stream.
public:
virtual void Serialize(System::IO::Stream ^ serializationStream, System::Object ^ graph);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("BinaryFormatter serialization is not trim compatible because the type of objects being processed cannot be statically discovered.")]
public void Serialize(System.IO.Stream serializationStream, object graph);
[System.Obsolete("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId="SYSLIB0011", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public void Serialize(System.IO.Stream serializationStream, object graph);
[System.Obsolete("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId="SYSLIB0011", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("BinaryFormatter serialization is not trim compatible because the Type of objects being processed cannot be statically discovered.")]
public void Serialize(System.IO.Stream serializationStream, object graph);
public void Serialize(System.IO.Stream serializationStream, object graph);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("BinaryFormatter serialization is not trim compatible because the type of objects being processed cannot be statically discovered.")>]
abstract member Serialize : System.IO.Stream * obj -> unit
override this.Serialize : System.IO.Stream * obj -> unit
[<System.Obsolete("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId="SYSLIB0011", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
abstract member Serialize : System.IO.Stream * obj -> unit
override this.Serialize : System.IO.Stream * obj -> unit
[<System.Obsolete("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId="SYSLIB0011", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("BinaryFormatter serialization is not trim compatible because the Type of objects being processed cannot be statically discovered.")>]
abstract member Serialize : System.IO.Stream * obj -> unit
override this.Serialize : System.IO.Stream * obj -> unit
abstract member Serialize : System.IO.Stream * obj -> unit
override this.Serialize : System.IO.Stream * obj -> unit
Public Sub Serialize (serializationStream As Stream, graph As Object)
Parameters
- serializationStream
- Stream
The stream to which the graph is to be serialized.
- graph
- Object
The object at the root of the graph to serialize.
Implements
- Attributes
Exceptions
An error has occurred during serialization, such as if an object in the graph parameter is not marked as serializable.
The caller does not have the required permission.
ASP.NET Core 5-8: Always thrown unless BinaryFormatter functionality is re-enabled in the project file. For more information, see Resolving BinaryFormatter obsoletion and disablement errors.
.NET 9 and later versions: In all cases. For more information, see BinaryFormatter migration guide.
Remarks
Warning
BinaryFormatter is insecure and can't be made secure. For more information, see the BinaryFormatter security guide.