fix: correct protobuf-net surrogate example in docs#932
Merged
Conversation
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.
This was referenced Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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