protobuf-net /protobuf-net
Protocol Buffers library for idiomatic .NET
★ 4,974⑂ 1,090👁 211⑃ 497● 886▤ 18
-1
Daily
4,974
stars
1,090
forks
211
watchers
497
prs
886
issues
18
releases
README
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.
Recent changes are on the releases page; older
history is in the release notes.
New: protobuf-net.Connect — the
Connect protocol for .NET. gRPC semantics over ordinary HTTP, so unary and
one-way streaming work over HTTP/1.1, through proxies and CDNs that will not carry gRPC. Reuses
protobuf-net.Grpc contracts unchanged; AOT-first; full conformance both directions.
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 true.
Runtime Installation
All stable and some pre-release packages are available on NuGet.
You can use the following command in the Package Manager Console:
ps
Install-Package protobuf-net
| Package | NuGet Stable | NuGet Pre-release | Downloads |
| ------- | ------------ | ----------------- | --------- |
| protobuf-net | | | |
Basic usage
1 First Decorate your classes
csharp
[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" :
csharp
var person = new Person {
Id = 12345, Name = "Fred",
Address = new Address {
Line1 = "Flat 1",
Line2 = "The Meadows"
}
};
using (var file = File.Create("person.biTop issues
#637Add class library package with protogen tool27 comments · 2020-05-05#687Generate Proto File(s)25 comments · 2020-07-31#278Method for serialising interfaces23 comments · 2017-07-13#895Issues with IL2CPP (Unity)22 comments · 2022-02-24#44DateTime serialization is broken ==> Should have an alternative DateTime serialization fully compliant with the .NET ecosystem 20 comments · 2014-11-07#845System.OutOfMemoryException: Array dimensions exceeded supported range. | for large object serialization18 comments · 2021-10-10#987[Question] Support of struct as sub-types17 comments · 2022-12-09#728Recreate code first data contracts from .proto files17 comments · 2020-11-17
Latest release
3.4.40 3.4.40 2026-10-21What's Changed Contract-first codegen: opt-out of unknown-field preservation (PreserveUnknownFields) by @mgravell in https://github.com/protobuf-net/protobuf-net/pull/1368 Fix StreamProtoReader pool state corruption after interrupted fixed-length deserialization by @PauloHMattos in https://github.com/protobuf-net/protobuf-net/pull/1376 Maintenance Drop the explicit Microsoft.SourceLink.GitHub reference by @mgravell in https://github.com/protobuf-net/protobuf-net/pull/1355 Bump Grpc.Net.Client from 2.83.0 to 2.84.0 by @dependabot[bot] in https://github.com/protobuf-net/protobuf-net/