Skip to main content
net8.0.NETStandard2.1

Google.Protobuf integration for Orleans.Serialization

Published
Jun 4, 2025
1y ago
Total Downloads
522.5K
522,506

Install

dotnet add package Microsoft.Orleans.Serialization.Protobuf --version 9.2.0-preview2
ProductVersions
.NET
net8.0
.NET Standard
netstandard2.1

README

Microsoft Orleans Serialization for Protobuf

Introduction

Microsoft Orleans Serialization for Protobuf provides Protocol Buffers (Protobuf) serialization support for Microsoft Orleans. Protobuf is a compact, efficient binary serialization format developed by Google, which is ideal for high-performance scenarios requiring efficient serialization and deserialization.

Getting Started

To use this package, install it via NuGet:

dotnet add package Microsoft.Orleans.Serialization.Protobuf

Example - Configuring Protobuf Serialization

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Orleans.Hosting;
using Orleans.Serialization;

var builder = Host.CreateApplicationBuilder(args)
    .UseOrleans(siloBuilder =>
    {
        siloBuilder
            .UseLocalhostClustering()
            // Configure Protobuf as a serializer
            .AddSerializer(serializerBuilder => serializerBuilder.AddProtobufSerializer());
    });

// Run the host
await builder.RunAsync();

Example - Using Protobuf with a Custom Type

using Orleans;
using ProtoBuf;

// Define a class with Protobuf attributes
[ProtoContract]
public class MyProtobufClass
{
    [ProtoMember(1)]
    public string Name { get; set; }
    
    [ProtoMember(2)]
    public int Age { get; set; }
    
    [ProtoMember(3)]
    public List<string> Tags { get; set; }
}

// You can use it directly in your grain interfaces and implementation
public interface IMyGrain : IGrainWithStringKey
{
    Task<MyProtobufClass> GetData();
    Task SetData(MyProtobufClass data);
}

public class MyGrain : Grain, IMyGrain
{
    private MyProtobufClass _data;

    public Task<MyProtobufClass> GetData()
    {
        return Task.FromResult(_data);
    }

    public Task SetData(MyProtobufClass data)
    {
        _data = data;
        return Task.CompletedTask;
    }
}

Example - Using .proto Files

You can also use standard .proto files and generate C# classes:

// MyData.proto
syntax = "proto3";

option csharp_namespace = "MyApp.Protos";

message Person {
  string name = 1;
  int32 age = 2;
  repeated string tags = 3;
}

Then reference the generated classes in your Orleans code:

using MyApp.Protos;
using Orleans;

public interface IPersonGrain : IGrainWithStringKey
{
    Task<Person> GetPerson();
    Task SetPerson(Person person);
}

public class PersonGrain : Grain, IPersonGrain
{
    private Person _person;

    public Task<Person> GetPerson()
    {
        return Task.FromResult(_person);
    }

    public Task SetPerson(Person person)
    {
        _person = person;
        return Task.CompletedTask;
    }
}

Documentation

For more comprehensive documentation, please refer to:

Feedback & Contributing

Changes from Previous Version

v9.2.0-preview1v9.2.0-preview2
Removed Dependencies
Microsoft.CSharp(.NETStandard2.1)

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 2 target frameworks; confirm the exact target used by your application.The published metadata declares 30 direct dependency entries across framework groups. Inspect the resolved dependency graph for your target framework.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.