Why protobuf-net survives renaming
protobuf-net serializes by the numeric tags in [ProtoMember(N)], not by member names — so renaming a protobuf-net DTO is safe on the wire, unlike System.Text.Json or DataContract where names ARE the contract. Here is why property renaming is largely free for protobuf-net, and the four cases that still break: implicit field numbering, ProtoInclude/AsReference type names, reflection models built by member-name, and ProtoEnum names.
Most advice about obfuscating serialized types is a warning: do not rename your DTOs, the names are the contract. That is correct for System.Text.Json, Newtonsoft.Json, and DataContract/WCF — the member name (or an attribute that restates it) is literally the key written to the wire, so renaming OrderId to a changes what the other side reads. protobuf-net is the happy exception, and the reason is worth understanding because it flips the usual guidance: for protobuf-net DTOs, property and field renaming is largely free, and you only have to think about a short list of exceptions.
The wire carries numbers, not names
protobuf-net implements Google’s Protocol Buffers wire format. Every field on the wire is a key/value pair, and the key is a varint built from a field number and a wire type — not a string. The field number comes from the N you wrote in [ProtoMember(N)]:
[ProtoContract]
public sealed class OrderLine
{
[ProtoMember(1)] public int OrderId { get; set; }
[ProtoMember(2)] public string Sku { get; set; } = "";
[ProtoMember(3)] public decimal UnitPrice { get; set; }
}
When this serializes, the bytes say “field 1, varint” then “field 2, length-delimited” and so on. The string "OrderId" appears nowhere in the output. That is the whole trick: the name is a compile-time label, and the tag number is the runtime contract.
Why that makes renaming safe
Because the name never reaches the wire, an obfuscator is free to rewrite it. After Nebula renames the type, a decompiler sees something like:
[ProtoContract]
public sealed class b
{
[ProtoMember(1)] public int a { get; set; }
[ProtoMember(2)] public string c { get; set; } = "";
[ProtoMember(3)] public decimal d { get; set; }
}
The [ProtoMember(N)] numbers are untouched — they are data in the attribute blob, not identifiers — so the serialized bytes are byte-for-byte identical to the un-obfuscated build. An old client that still has the original OrderLine reads the renamed server’s output perfectly, and vice versa, because both sides agree that field 3 is the unit price. The human-readable name was only ever for your source tree, and obfuscation is exactly the transform that throws your source tree away.
This is a genuine advantage over the name-based serializers. With System.Text.Json, renaming UnitPrice to d either changes the JSON key to "d" (breaking every consumer) or forces you to pin every property with [JsonPropertyName("UnitPrice")] — at which point you have re-introduced the very string you were trying to hide. protobuf-net needs none of that. Use explicit [ProtoMember(N)] numbering and the rename is free.
The four things that still break
The freedom above holds precisely because the tag is explicit and the name is absent. Each exception below is a case where that stops being true — either the tag depends on the name, or the name sneaks onto the wire or into a reflection lookup.
1. Implicit field numbering
protobuf-net can assign tags for you:
[ProtoContract(ImplicitFields = ImplicitFields.AllPublic)]
public sealed class Customer // DANGER under rename
{
public int Id { get; set; } // implicitly tag 1
public string Name { get; set; } // implicitly tag 2
public string Region { get; set; } // implicitly tag 3
}
With ImplicitFields.AllPublic (or AllFields), there are no explicit numbers. protobuf-net derives the tags by enumerating the members and ordering them alphabetically by name, then numbering from 1. Rename Name to a and Region to b and the alphabetical order changes, so the tags that used to be Id=1, Name=2, Region=3 silently become something else — every field shifts, and the wire format breaks against any previously serialized data. Reordering members by hand does the same thing.
The fix is to not rely on implicit numbering for anything you obfuscate. Either convert the type to explicit [ProtoMember(N)] (the recommended move — it is both rename-safe and version-safe), or keep-list the type so its members keep their names.
2. ProtoInclude, AsReference, and dynamic type handling
Inheritance and reference tracking can put a type name into play:
[ProtoContract]
[ProtoInclude(10, typeof(ExpressShipment))]
public abstract class Shipment { [ProtoMember(1)] public string Tracking { get; set; } = ""; }
The [ProtoInclude(10, typeof(ExpressShipment))] form is tag-based (field 10) and therefore rename-safe — the subtype is identified by the number 10, not by "ExpressShipment". But two related features are not safe by default: AsReference graph serialization and DynamicType can embed the assembly-qualified CLR type name so the reader can rehydrate the exact type. If you rename the type, that embedded string no longer matches. Prefer tag-based [ProtoInclude(N, typeof(T))] over DynamicType, and if you must serialize AsReference across process boundaries, keep-list the affected types.
3. A runtime model built by member name
If you configure protobuf-net imperatively instead of with attributes, you may be naming members as strings:
RuntimeTypeModel.Default
.Add(typeof(Customer), applyDefaultBehaviour: false)
.Add(1, "Id")
.Add(2, "Name") // string lookup — breaks after rename
.Add(3, "Region");
.Add(2, "Name") resolves "Name" by reflection at startup. After Nebula renames the property to a, the string "Name" no longer matches any member and the model fails to build (or silently skips the field). This is the one case that is genuinely incompatible with renaming, so these types belong on the keep-list — or, better, migrate the registration to the strongly-typed overload .Add(2, nameof(Customer.Name)) and then keep-list, since nameof is still a compile-time string baked into IL.
4. ProtoEnum names
Enum values serialize by their numeric value, so renaming enum members is normally fine. The exception is an explicit name round-trip:
[ProtoContract]
public enum Priority
{
[ProtoEnum(Name = "LOW")] Low = 0,
[ProtoEnum(Name = "HIGH")] High = 2,
}
[ProtoEnum(Name = "...")] is a string literal in the attribute, so it is not affected by renaming the enum member — but it is still a readable string in your metadata, and if any tooling matches on that name you want to leave it alone. Plain enums without [ProtoEnum(Name=)] need no special handling at all.
The keep-list: narrow by design
Put everything on full renaming, then exempt only the specific types that fall into cases 1–3 above. A realistic nebula.config.json:
{
"input": "bin/Release/net8.0/Acme.Orders.dll",
"output": "dist/Acme.Orders.dll",
"rename": { "enabled": true, "scope": "all" },
"strings": { "encrypt": true },
"controlFlow": { "flatten": "sensitive" },
"keep": [
{
"type": "Acme.Orders.Dtos.Customer",
"members": "names",
"reason": "ImplicitFields.AllPublic — tags derive from member names/order"
},
{
"type": "Acme.Orders.Model.*",
"members": "names",
"reason": "RuntimeTypeModel built with .Add(n, \"MemberName\") by string"
}
]
}
"members": "names" preserves the member names for those types while still letting Nebula apply string encryption and control-flow transforms to their method bodies — you are only protecting the names the serializer needs, not exempting the type wholesale. Then protect the assembly:
nebula protect --config nebula.config.json
Everything outside the keep-list — which for a well-numbered protobuf-net project is essentially the entire DTO layer — gets renamed freely with no wire-format risk.
The rule of thumb
protobuf-net inverts the usual serialization-vs-obfuscation tension. Because the contract is the numeric tag and not the member name, explicit [ProtoMember(N)] DTOs are rename-safe by construction. Spend your effort in one place: find the types that let the name leak back into the contract — implicit numbering, AsReference/DynamicType, and string-named runtime models — convert what you can to explicit tags, keep-list the rest, and let Nebula rename the whole DTO layer without a second thought.
Try Nebula.NET
Harden your .NET code in minutes — start with the free edition.