BinaryFormatter.Serialize Metod

Definition

Serialiserar ett objekt, eller ett diagram över anslutna objekt, till den angivna strömmen.

Överlagringar

Name Description
Serialize(Stream, Object)
Föråldrad.

Serialiserar objektet eller grafen med objekt med angiven topp (rot) till den angivna strömmen.

Serialize(Stream, Object, Header[])

Serialiserar objektet eller grafen med objekt med angiven topp (rot) till den angivna strömmen som kopplar de angivna rubrikerna.

Serialize(Stream, Object)

Källa:
BinaryFormatter.Removed.cs
Källa:
BinaryFormatter.Core.cs
Källa:
BinaryFormatter.Removed.cs
Källa:
BinaryFormatter.Core.cs
Källa:
BinaryFormatter.Core.cs
Källa:
BinaryFormatter.Core.cs
Källa:
BinaryFormatter.Core.cs

Varning

BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.

Serialiserar objektet eller grafen med objekt med angiven topp (rot) till den angivna strömmen.

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)

Parametrar

serializationStream
Stream

Dataströmmen som diagrammet ska serialiseras till.

graph
Object

Objektet i grafens rot som ska serialiseras.

Implementeringar

Attribut

Undantag

serializationStream är null.

-eller-

Är graph null.

Ett fel har uppstått under serialiseringen, till exempel om ett objekt i parametern graph inte har markerats som serialiserbart.

Anroparen har inte den behörighet som krävs.

ASP.NET Core 5-8: Kastas alltid om inte BinaryFormatter funktioner återaktiveras i projektfilen. Mer information finns i Lösa binaryFormatter-obsoletions- och inaktiveringsfel.

.NET 9 och senare versioner: I samtliga fall. Mer information finns i migreringsguiden för BinaryFormatter.

Kommentarer

Varning

BinaryFormatter är osäker och kan inte göras säker. Mer information finns i säkerhetsguiden för BinaryFormatter.

Gäller för

Serialize(Stream, Object, Header[])

Serialiserar objektet eller grafen med objekt med angiven topp (rot) till den angivna strömmen som kopplar de angivna rubrikerna.

public:
 virtual void Serialize(System::IO::Stream ^ serializationStream, System::Object ^ graph, cli::array <System::Runtime::Remoting::Messaging::Header ^> ^ headers);
public void Serialize(System.IO.Stream serializationStream, object graph, System.Runtime.Remoting.Messaging.Header[] headers);
abstract member Serialize : System.IO.Stream * obj * System.Runtime.Remoting.Messaging.Header[] -> unit
override this.Serialize : System.IO.Stream * obj * System.Runtime.Remoting.Messaging.Header[] -> unit
Public Sub Serialize (serializationStream As Stream, graph As Object, headers As Header())

Parametrar

serializationStream
Stream

Dataströmmen som objektet ska serialiseras till.

graph
Object

Objektet i grafens rot som ska serialiseras.

headers
Header[]

Fjärrkommunikationshuvuden som ska inkluderas i serialiseringen. Kan vara null.

Implementeringar

Undantag

serializationStream är null.

Ett fel har uppstått under serialiseringen, till exempel om ett objekt i parametern graph inte har markerats som serialiserbart.

Anroparen har inte den behörighet som krävs.

Kommentarer

Varning

BinaryFormatter är osäker och kan inte göras säker. Mer information finns i säkerhetsguiden för BinaryFormatter.

Serialiseringsprocessen innehåller den information som anges i parametern headers längst fram i den serialiserade dataströmmen.

Rubriker används endast för specifika fjärrkommunikationsprogram.

Gäller för