Fast, flexible, and version-tolerant serializer for .NET
$ dotnet add package Microsoft.Orleans.SerializationMicrosoft Orleans Serialization is a fast, flexible, and version-tolerant serializer for .NET. It provides the core serialization capabilities for Orleans, enabling efficient serialization and deserialization of data across the network and for storage.
To use this package, install it via NuGet:
dotnet add package Microsoft.Orleans.Serialization
This package is automatically included when you reference the Orleans SDK or the Orleans client/server metapackages.
// Creating a serializer
var services = new ServiceCollection();
services.AddSerializer();
var serviceProvider = services.BuildServiceProvider();
var serializer = serviceProvider.GetRequiredService<Serializer>();
// Serializing an object
var bytes = serializer.SerializeToArray(myObject);
// Deserializing an object
var deserializedObject = serializer.Deserialize<MyType>(bytes);
To make your types serializable in Orleans, mark them with the [GenerateSerializer] attribute and mark each field/property which should be serialized with the [Id(int)] attribute:
[GenerateSerializer]
public class MyClass
{
[Id(0)]
public string Name { get; set; }
[Id(1)]
public int Value { get; set; }
}
For more comprehensive documentation, please refer to: