protobuf-net 3.3.21

Prefix Reserved
dotnet add package protobuf-net --version 3.3.21
                    
NuGet\Install-Package protobuf-net -Version 3.3.21
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="protobuf-net" Version="3.3.21" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="protobuf-net" Version="3.3.21" />
                    
Directory.Packages.props
<PackageReference Include="protobuf-net" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add protobuf-net --version 3.3.21
                    
#r "nuget: protobuf-net, 3.3.21"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package protobuf-net@3.3.21
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=protobuf-net&version=3.3.21
                    
Install as a Cake Addin
#tool nuget:?package=protobuf-net&version=3.3.21
                    
Install as a Cake Tool

protobuf-net

protobuf-net logo protobuf-net is a contract based serializer for .NET code, that happens to write data in the "protocol buffers" serialization format engineered by Google. The API, however, is very different to Google's, and follows typical .NET patterns (it is broadly comparable, in usage, to XmlSerializer, DataContractSerializer, etc). It should work for most .NET languages that write standard types and can use attributes.

.NET

Recent changes are on the releases page; older history is in the release notes.

Online tools: protobuf-net.dev

Free, browser-based, and nothing to install — and it all runs locally: it is a static site, so your schemas and payloads never leave your machine. You can:

  • generate C#/VB types from a .proto schema — the same code generation as the protogen global tool
  • decode a raw protobuf payload, without needing the schema that produced it

Documentation is at docs.protobuf-net.dev.

Supported Runtimes

  • .NET 6.0+ (.NET 5 etc will use .NET Standard 2.1)
  • .NET Standard 2.0, 2.1
  • .NET Framework 4.6.2+

Native AOT and trimming

From 3.3, protobuf-net can generate serializers at build time from code-first contracts, making native AOT and trimming work — and improving cold start even on ordinary JIT builds. See the AOT documentation.

The build tools (analyzers that validate contracts, and this generator) are included in the protobuf-net package by default; opt out with <ProtoBufDisableBuildTools>true</ProtoBufDisableBuildTools>.

Runtime Installation

All stable and some pre-release packages are available on NuGet.

You can use the following command in the Package Manager Console:

Install-Package protobuf-net
Package NuGet Stable NuGet Pre-release Downloads
protobuf-net protobuf-net protobuf-net protobuf-net

Basic usage

1 First Decorate your classes

[ProtoContract]
class Person {
    [ProtoMember(1)]
    public int Id {get;set;}
    [ProtoMember(2)]
    public string Name {get;set;}
    [ProtoMember(3)]
    public Address Address {get;set;}
}
[ProtoContract]
class Address {
    [ProtoMember(1)]
    public string Line1 {get;set;}
    [ProtoMember(2)]
    public string Line2 {get;set;}
}

Note that unlike XmlSerializer, the member-names are not encoded in the data - instead, you must pick an integer to identify each member. Additionally, to show intent it is necessary to show that we intend this type to be serialized (i.e. that it is a data contract).

2 Serialize your data

This writes a 32 byte file to "person.bin" :

var person = new Person {
    Id = 12345, Name = "Fred",
    Address = new Address {
        Line1 = "Flat 1",
        Line2 = "The Meadows"
    }
};
using (var file = File.Create("person.bin")) {
    Serializer.Serialize(file, person);
}

3 Deserialize your data

This reads the data back from "person.bin" :

Person newPerson;
using (var file = File.OpenRead("person.bin")) {
    newPerson = Serializer.Deserialize<Person>(file);
}

Notes

Notes for Identifiers
  • they must be positive integers (for best portability, they should be <= 536870911 and not in the range 19000-19999)
  • they must be unique within a single type but the same numbers can be re-used in sub-types if inheritance is enabled
  • the identifiers must not conflict with any inheritance identifiers (discussed later)
  • lower numbers take less space - don't start at 100,000,000
  • the identifier is important; you can change the member-name, or shift it between a property and a field, but changing the identifier changes the data

Advanced subjects

Inheritance

Inheritance must be explicitly declared, in a similar way that it must for XmlSerializer and DataContractSerializer. This is done via [ProtoInclude(...)] on each type with known sub-types:

[ProtoContract]
[ProtoInclude(7, typeof(SomeDerivedType))]
class SomeBaseType {...}

[ProtoContract]
class SomeDerivedType {...}

There is no special significance in the 7 above; it is an integer key, just like every [ProtoMember(...)]. It must be unique in terms of SomeBaseType (no other [ProtoInclude(...)] or [ProtoMember(...)] in SomeBaseType can use 7), but does not need to be unique globally.

.proto file

As an alternative to writing your classes and decorating them, you can generate your types from a .proto schema using the protogen tool, available as a multi-platform "global tool", or in your browser at protobuf-net.dev (see Online tools, above).

Alternative to attributes

In v2+, everything that can be done with attributes can also be configured at runtime via RuntimeTypeModel. The Serializer.* methods are basically just shortcuts to RuntimeTypeModel.Default., so to manipulate the behaviour of Serializer., you must configure RuntimeTypeModel.Default.

Support

I try to be responsive to Stack Overflow questions in the protobuf-net tag, issues logged on GitHub, email, etc. I don't currently offer a paid support channel. If I've helped you, feel free to buy me a coffee or see the "Sponsor" link at the top of the GitHub page.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (990)

Showing the top 5 NuGet packages that depend on protobuf-net:

Package Downloads
App.Metrics.Formatters.Prometheus

App Metrics Formatting, formatting metrics data to Prometheus formats.

ProtoBufJsonConverter

Convert a protobuf message to a JSON string or object (and back) using the proto definition file.

protobuf-net.Grpc

Package Description

EventStore.Client

The legacy TCP client API for Event Store. Get the open source or commercial versions of Event Store server from https://eventstore.com/

protobuf-net.Grpc.Reflection

Package Description

GitHub repositories (204)

Showing the top 20 popular GitHub repositories that depend on protobuf-net:

Repository Stars
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
QuantConnect/Lean
Lean Algorithmic Trading Engine by QuantConnect (Python, C#)
JosefNemec/Playnite
Video game library manager with support for wide range of 3rd party libraries and game emulation support, providing one unified interface for your games.
aspnetboilerplate/aspnetboilerplate
ASP.NET Boilerplate - Web Application Framework
dotnet/orleans
Cloud Native application framework for .NET
quasar/Quasar
Remote Administration Tool for Windows
PixiEditor/PixiEditor
PixiEditor is a Universal Editor for all your 2D needs
MessagePack-CSharp/MessagePack-CSharp
Extremely Fast MessagePack Serializer for C#(.NET, .NET Core, Unity, Xamarin). / msgpack.org[C#]
andrewmd5/Borderless-Gaming
Play your favorite games in a borderless window; no more time consuming alt-tabs.
Facepunch/sbox-public
s&box is a modern game engine, built on Valve's Source 2 and the latest .NET technology, it provides a modern intuitive editor for creating games
ServiceStack/ServiceStack
Thoughtfully architected, obscenely fast, thoroughly enjoyable web services for all
anjoy8/Blog.Core
💖 ASP.NET Core 8.0 全家桶教程,前后端分离后端接口,vue教程姊妹篇,官方文档:
Cysharp/MemoryPack
Zero encoding extreme performance binary serializer for C# and Unity.
stratumauth/app
📱 Two-Factor Authentication (2FA) client for Android + Wear OS
PCL-Community/PCL-CE
PCL 社区版 由社区开发者维护与管理
huynhsontung/Screenbox
LibVLC-based media player for the Universal Windows Platform
ZiggyCreatures/FusionCache
FusionCache is an easy to use, fast and robust hybrid cache with advanced resiliency features.
0x90d/videoduplicatefinder
Video Duplicate Finder - Crossplatform
linq2db/linq2db
Linq to database provider.
SteamRE/DepotDownloader
Steam depot downloader utilizing the SteamKit2 library.
Version Downloads Last Updated
3.3.21 0 8/17/2026
3.3.8 18,447 8/11/2026
3.3.0 920 8/11/2026
3.2.56 10,355,860 7/31/2025
3.2.55 109,618 7/27/2025
3.2.52 17,807,134 4/11/2025
3.2.46 5,195,481 1/24/2025
3.2.45 9,468,112 10/23/2024
3.2.30 25,943,505 9/27/2023
3.2.26 6,719,964 5/25/2023
3.2.16 3,072,149 3/17/2023
3.2.12 706,123 3/4/2023
3.2.8 107,294 2/27/2023
3.2.0 219,979 2/20/2023
3.1.33 4,074,768 1/30/2023
3.1.26 1,857,855 12/16/2022
2.4.9 772,945 2/10/2025
2.4.8 13,166,718 1/9/2023
Loading failed