# ObjectSerializer Methods

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/)

## CanSerialize(Type) {#canserialize-system-type-dadbd7ca}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/canserialize-system-type-dadbd7ca/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs#L1390)

```csharp
public bool CanSerialize(Type type)
```

Returns `true` if the provided type, `type`, can be serialized, and `false` otherwise.

### Parameters

- `type` (`Type`)

## Deserialize(ArraySegment&lt;byte&gt;, SerializerSession, Type) {#deserialize-system-arraysegment-byte-orleans-serialization-session-serializerses-674a5297}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/deserialize-system-arraysegment-byte-orleans-serialization-session-serializerses-674a5297/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public object Deserialize(ArraySegment<byte> source, SerializerSession session, Type type)
```

Deserialize a value of type `type` from `source`.

### Parameters

- `source` (`ArraySegment<byte>`): The source buffer.
- `session` (`SerializerSession`): The serializer session.
- `type` (`Type`): The expected type of the value.

### Returns

The deserialized value.

## Deserialize(ArraySegment&lt;byte&gt;, Type) {#deserialize-system-arraysegment-byte-system-type-c0e68927}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/deserialize-system-arraysegment-byte-system-type-c0e68927/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public object Deserialize(ArraySegment<byte> source, Type type)
```

Deserialize a value of type `type` from `source`.

### Parameters

- `source` (`ArraySegment<byte>`): The source buffer.
- `type` (`Type`): The expected type of the value.

### Returns

The deserialized value.

## Deserialize(ReadOnlyMemory&lt;byte&gt;, SerializerSession, Type) {#deserialize-system-readonlymemory-byte-orleans-serialization-session-serializers-3b7384b0}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/deserialize-system-readonlymemory-byte-orleans-serialization-session-serializers-3b7384b0/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public object Deserialize(ReadOnlyMemory<byte> source, SerializerSession session, Type type)
```

Deserialize a value of type `type` from `source`.

### Parameters

- `source` (`ReadOnlyMemory<byte>`): The source buffer.
- `session` (`SerializerSession`): The serializer session.
- `type` (`Type`): The expected type of the value.

### Returns

The deserialized value.

## Deserialize(ReadOnlyMemory&lt;byte&gt;, Type) {#deserialize-system-readonlymemory-byte-system-type-9f34df36}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/deserialize-system-readonlymemory-byte-system-type-9f34df36/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public object Deserialize(ReadOnlyMemory<byte> source, Type type)
```

Deserialize a value of type `type` from `source`.

### Parameters

- `source` (`ReadOnlyMemory<byte>`): The source buffer.
- `type` (`Type`): The expected type of the value.

### Returns

The deserialized value.

## Deserialize(ReadOnlySequence&lt;byte&gt;, SerializerSession, Type) {#deserialize-system-buffers-readonlysequence-byte-orleans-serialization-session-s-7f950fa6}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/deserialize-system-buffers-readonlysequence-byte-orleans-serialization-session-s-7f950fa6/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public object Deserialize(ReadOnlySequence<byte> source, SerializerSession session, Type type)
```

Deserialize a value of type `type` from `source`.

### Parameters

- `source` (`ReadOnlySequence<byte>`): The source buffer.
- `session` (`SerializerSession`): The serializer session.
- `type` (`Type`): The expected type of the value.

### Returns

The deserialized value.

## Deserialize(ReadOnlySequence&lt;byte&gt;, Type) {#deserialize-system-buffers-readonlysequence-byte-system-type-45b3b560}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/deserialize-system-buffers-readonlysequence-byte-system-type-45b3b560/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public object Deserialize(ReadOnlySequence<byte> source, Type type)
```

Deserialize a value of type `type` from `source`.

### Parameters

- `source` (`ReadOnlySequence<byte>`): The source buffer.
- `type` (`Type`): The expected type of the value.

### Returns

The deserialized value.

## Deserialize(ReadOnlySpan&lt;byte&gt;, SerializerSession, Type) {#deserialize-system-readonlyspan-byte-orleans-serialization-session-serializerses-0d7c5e2b}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/deserialize-system-readonlyspan-byte-orleans-serialization-session-serializerses-0d7c5e2b/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public object Deserialize(ReadOnlySpan<byte> source, SerializerSession session, Type type)
```

Deserialize a value of type `type` from `source`.

### Parameters

- `source` (`ReadOnlySpan<byte>`): The source buffer.
- `session` (`SerializerSession`): The serializer session.
- `type` (`Type`): The expected type of the value.

### Returns

The deserialized value.

## Deserialize(ReadOnlySpan&lt;byte&gt;, Type) {#deserialize-system-readonlyspan-byte-system-type-d95e2ce3}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/deserialize-system-readonlyspan-byte-system-type-d95e2ce3/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public object Deserialize(ReadOnlySpan<byte> source, Type type)
```

Deserialize a value of type `type` from `source`.

### Parameters

- `source` (`ReadOnlySpan<byte>`): The source buffer.
- `type` (`Type`): The expected type of the value.

### Returns

The deserialized value.

## Deserialize(Stream, SerializerSession, Type) {#deserialize-system-io-stream-orleans-serialization-session-serializersession-sys-729d7c8d}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/deserialize-system-io-stream-orleans-serialization-session-serializersession-sys-729d7c8d/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public object Deserialize(Stream source, SerializerSession session, Type type)
```

Deserialize a value of type `type` from `source`.

### Parameters

- `source` (`Stream`): The source buffer.
- `session` (`SerializerSession`): The serializer session.
- `type` (`Type`): The expected type of the value.

### Returns

The deserialized value.

## Deserialize(Stream, Type) {#deserialize-system-io-stream-system-type-73c79629}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/deserialize-system-io-stream-system-type-73c79629/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public object Deserialize(Stream source, Type type)
```

Deserialize a value of type `type` from `source`.

### Parameters

- `source` (`Stream`): The source buffer.
- `type` (`Type`): The expected type of the value.

### Returns

The deserialized value.

## Deserialize(byte[], SerializerSession, Type) {#deserialize-byte-array-1-orleans-serialization-session-serializersession-system-30c9d323}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/deserialize-byte-array-1-orleans-serialization-session-serializersession-system-30c9d323/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public object Deserialize(byte[] source, SerializerSession session, Type type)
```

Deserialize a value of type `type` from `source`.

### Parameters

- `source` (`byte[]`): The source buffer.
- `session` (`SerializerSession`): The serializer session.
- `type` (`Type`): The expected type of the value.

### Returns

The deserialized value.

## Deserialize(byte[], Type) {#deserialize-byte-array-1-system-type-9ffa805b}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/deserialize-byte-array-1-system-type-9ffa805b/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public object Deserialize(byte[] source, Type type)
```

Deserialize a value of type `type` from `source`.

### Parameters

- `source` (`byte[]`): The source buffer.
- `type` (`Type`): The expected type of the value.

### Returns

The deserialized value.

## Deserialize(Reader&lt;TInput&gt;, Type) {#deserialize-1-ref-orleans-serialization-buffers-reader-tinput-system-type-b4d369b5}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/deserialize-1-ref-orleans-serialization-buffers-reader-tinput-system-type-b4d369b5/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public object Deserialize<TInput>(ref Reader<TInput> source, Type type)
```

Deserialize a value of type `type` from `source`.

### Parameters

- `source` (`Reader<TInput>`): The source buffer.
- `type` (`Type`): The expected type of the value.

### Returns

The deserialized value.

## Serialize(object, ArraySegment&lt;byte&gt;, SerializerSession, Type) {#serialize-object-system-arraysegment-byte-orleans-serialization-session-serializ-e5f4050b}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/serialize-object-system-arraysegment-byte-orleans-serialization-session-serializ-e5f4050b/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public int Serialize(object value, ArraySegment<byte> destination, SerializerSession session, Type type)
```

Serializes the provided `value` into `destination`.

### Parameters

- `value` (`object`): The value to serialize.
- `destination` (`ArraySegment<byte>`): The destination where serialized data will be written.
- `session` (`SerializerSession`): The serializer session.
- `type` (`Type`): The expected type of the value.

### Returns

The length of the serialized data.

## Serialize(object, ArraySegment&lt;byte&gt;, Type) {#serialize-object-system-arraysegment-byte-system-type-1c8caac3}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/serialize-object-system-arraysegment-byte-system-type-1c8caac3/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public int Serialize(object value, ArraySegment<byte> destination, Type type)
```

Serializes the provided `value` into `destination`.

### Parameters

- `value` (`object`): The value to serialize.
- `destination` (`ArraySegment<byte>`): The destination where serialized data will be written.
- `type` (`Type`): The expected type of the value.

### Returns

The length of the serialized data.

## Serialize(object, byte[], SerializerSession, Type) {#serialize-object-byte-array-1-orleans-serialization-session-serializersession-sy-9811702b}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/serialize-object-byte-array-1-orleans-serialization-session-serializersession-sy-9811702b/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public int Serialize(object value, byte[] destination, SerializerSession session, Type type)
```

Serializes the provided `value` into `destination`.

### Parameters

- `value` (`object`): The value to serialize.
- `destination` (`byte[]`): The destination where serialized data will be written.
- `session` (`SerializerSession`): The serializer session.
- `type` (`Type`): The expected type of the value.

### Returns

The length of the serialized data.

## Serialize(object, byte[], Type) {#serialize-object-byte-array-1-system-type-40d5e2e3}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/serialize-object-byte-array-1-system-type-40d5e2e3/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public int Serialize(object value, byte[] destination, Type type)
```

Serializes the provided `value` into `destination`.

### Parameters

- `value` (`object`): The value to serialize.
- `destination` (`byte[]`): The destination where serialized data will be written.
- `type` (`Type`): The expected type of the value.

### Returns

The length of the serialized data.

## Serialize(object, Stream, SerializerSession, Type, int) {#serialize-object-system-io-stream-orleans-serialization-session-serializersessio-7a197b68}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/serialize-object-system-io-stream-orleans-serialization-session-serializersessio-7a197b68/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs#L1467-L1486)

```csharp
public void Serialize(object value, Stream destination, SerializerSession session, Type type, int sizeHint = 0)
```

Serializes the provided `value` into `destination`.

### Parameters

- `value` (`object`): The value to serialize.
- `destination` (`Stream`): The destination where serialized data will be written.
- `session` (`SerializerSession`): The serializer session.
- `type` (`Type`): The expected type of the value.
- `sizeHint` (`int`): The estimated upper bound for the length of the serialized data.

## Serialize(object, Stream, Type, int) {#serialize-object-system-io-stream-system-type-int-28489d66}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/serialize-object-system-io-stream-system-type-int-28489d66/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs#L1434-L1454)

```csharp
public void Serialize(object value, Stream destination, Type type, int sizeHint = 0)
```

Serializes the provided `value` into `destination`.

### Parameters

- `value` (`object`): The value to serialize.
- `destination` (`Stream`): The destination where serialized data will be written.
- `type` (`Type`): The expected type of the value.
- `sizeHint` (`int`): The estimated upper bound for the length of the serialized data.

## Serialize(object, Memory&lt;byte&gt;, SerializerSession, Type) {#serialize-object-ref-system-memory-byte-orleans-serialization-session-serializer-6a802e54}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/serialize-object-ref-system-memory-byte-orleans-serialization-session-serializer-6a802e54/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public void Serialize(object value, ref Memory<byte> destination, SerializerSession session, Type type)
```

Serializes the provided `value` into `destination`.

### Parameters

- `value` (`object`): The value to serialize.
- `destination` (`Memory<byte>`): The destination where serialized data will be written.
- `session` (`SerializerSession`): The serializer session.
- `type` (`Type`): The expected type of the value.

## Serialize(object, Memory&lt;byte&gt;, Type) {#serialize-object-ref-system-memory-byte-system-type-d5278872}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/serialize-object-ref-system-memory-byte-system-type-d5278872/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public void Serialize(object value, ref Memory<byte> destination, Type type)
```

Serializes the provided `value` into `destination`.

### Parameters

- `value` (`object`): The value to serialize.
- `destination` (`Memory<byte>`): The destination where serialized data will be written.
- `type` (`Type`): The expected type of the value.

## Serialize(object, Span&lt;byte&gt;, SerializerSession, Type) {#serialize-object-ref-system-span-byte-orleans-serialization-session-serializerse-4553ee79}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/serialize-object-ref-system-span-byte-orleans-serialization-session-serializerse-4553ee79/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public void Serialize(object value, ref Span<byte> destination, SerializerSession session, Type type)
```

Serializes the provided `value` into `destination`.

### Parameters

- `value` (`object`): The value to serialize.
- `destination` (`Span<byte>`): The destination where serialized data will be written.
- `session` (`SerializerSession`): The serializer session.
- `type` (`Type`): The expected type of the value.

## Serialize(object, Span&lt;byte&gt;, Type) {#serialize-object-ref-system-span-byte-system-type-cc2bc82d}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/serialize-object-ref-system-span-byte-system-type-cc2bc82d/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public void Serialize(object value, ref Span<byte> destination, Type type)
```

Serializes the provided `value` into `destination`.

### Parameters

- `value` (`object`): The value to serialize.
- `destination` (`Span<byte>`): The destination where serialized data will be written.
- `type` (`Type`): The expected type of the value.

## Serialize(object, TBufferWriter, SerializerSession, Type) {#serialize-1-object-tbufferwriter-orleans-serialization-session-serializersession-f5642ce4}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/serialize-1-object-tbufferwriter-orleans-serialization-session-serializersession-f5642ce4/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public void Serialize<TBufferWriter>(object value, TBufferWriter destination, SerializerSession session, Type type)
```

Serializes the provided `value` into `destination`.

### Parameters

- `value` (`object`): The value to serialize.
- `destination` (`TBufferWriter`): The destination where serialized data will be written.
- `session` (`SerializerSession`): The serializer session.
- `type` (`Type`): The expected type of the value.

## Serialize(object, TBufferWriter, Type) {#serialize-1-object-tbufferwriter-system-type-35a8ba22}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/serialize-1-object-tbufferwriter-system-type-35a8ba22/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public void Serialize<TBufferWriter>(object value, TBufferWriter destination, Type type)
```

Serializes the provided `value` into `destination`.

### Parameters

- `value` (`object`): The value to serialize.
- `destination` (`TBufferWriter`): The destination where serialized data will be written.
- `type` (`Type`): The expected type of the value.

## Serialize(object, Writer&lt;TBufferWriter&gt;, Type) {#serialize-1-object-ref-orleans-serialization-buffers-writer-tbufferwriter-system-507eeb02}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.objectserializer/methods/serialize-1-object-ref-orleans-serialization-buffers-writer-tbufferwriter-system-507eeb02/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Serialization/Serializer.cs)

```csharp
public void Serialize<TBufferWriter>(object value, ref Writer<TBufferWriter> destination, Type type)
```

Serializes the provided `value` into `destination`.

### Parameters

- `value` (`object`): The value to serialize.
- `destination` (`Writer<TBufferWriter>`): The destination where serialized data will be written.
- `type` (`Type`): The expected type of the value.
