Skip to content

fix: correct protobuf-net surrogate example in docs#932

Merged
SteveDunn merged 7 commits into
mainfrom
bugfix-838
May 6, 2026
Merged

fix: correct protobuf-net surrogate example in docs#932
SteveDunn merged 7 commits into
mainfrom
bugfix-838

Conversation

@SteveDunn

Copy link
Copy Markdown
Owner

The documented pattern [ProtoContract(Surrogate = typeof(string))] does not work with protobuf-net v3 because string (and other primitives) are built-in types that cannot be registered as surrogates. The library throws 'Data of this type has inbuilt behaviour, and cannot be added to a model in this way: System.String' at runtime, both during normal serialization setup and when using SchemaGenerator.

Replace with the correct pattern: a dedicated surrogate DTO class annotated with [ProtoContract] and [ProtoMember(1)], with implicit conversion operators to/from the value object.

Fixes #838

SteveDunn and others added 7 commits May 5, 2026 22:06
The documented pattern [ProtoContract(Surrogate = typeof(string))]
does not work with protobuf-net v3 because string (and other primitives)
are built-in types that cannot be registered as surrogates. The library
throws 'Data of this type has inbuilt behaviour, and cannot be added to
a model in this way: System.String' at runtime, both during normal
serialization setup and when using SchemaGenerator.

Replace with the correct pattern: a dedicated surrogate DTO class
annotated with [ProtoContract] and [ProtoMember(1)], with implicit
conversion operators to/from the value object.

Fixes #838

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Merged decision from .squad/decisions/inbox/fenster-proto-surrogate-fix.md
- Documented root cause: invalid protobuf pattern in original docs
- Solution: use surrogate DTO class instead of primitive type
- Updated .squad/decisions.md with final decision record
- Deleted processed inbox file

Files Modified:
- .squad/decisions.md: Added decision entry for issue #838 fix
- Removed: .squad/decisions/inbox/fenster-proto-surrogate-fix.md

Previous work by Fenster + Coordinator:
- Fixed README.md with correct surrogate DTO pattern
- Updated FAQ.md with working example and explanatory note
- Commit: 6f6e919

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Introduced `GrpcScenario` for serialization and conversion examples.
- Added `BoxId` value object with protobuf surrogate pattern implementation.
- Integrated `protobuf-net` and `protobuf-net.Grpc` packages.
- Registered new gRPC dependencies in `.csproj`.
- Updated `Program.cs` to include gRPC scenario execution.
…oved value objects

- Removed outdated `BoxIdSurrogate` and protobuf surrogate implementation.
- Introduced `Person` model with composite properties (`Name`, `Age`, `BoxId`, `Temperature`).
- Updated gRPC service to return `Person` instead of `BoxId`.
- Refactored `Program.cs` and `GrpcScenario` to match new API design.
- Improved value object declarations with generic surrogate support.
- FAQ now shows the generic VogenSurrogate<TW, TP> approach from the
  GrpcScenario example, which works across all value object types
- FAQ links to samples/Vogen.Examples/SerializationAndConversion/Grpc/GrpcScenario.cs
  for a full working example with schema generation and a gRPC service
- README no longer duplicates the content; points to FAQ instead

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Restore the original pre-v3 surrogate=typeof(string) pattern with attribution
- Add a v3+ section explaining why primitives cannot be used as surrogates
- Fix the generic VogenSurrogate<TW, TP>: implicit operators now use TW/TP
  type params instead of the hardcoded BoxId type
- Separate the surrogate class definition from the usage examples for clarity

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Clarified protobuf-net usage in FAQ: added version-dependent note and corrected `[ProtoContract(Surrogate = typeof(string))]` example with placeholder.
- Improved `VogenSurrogate<TW, TP>` in `GrpcScenario` with proper type parameter usage in implicit operators and fixed underlying type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Surrogate not working for protobuf-net

1 participant