Skip to content

Fix broken code samples in docs content#520

Merged
externl merged 1 commit into
icerpc:mainfrom
externl:fix-content-code-samples
Jul 8, 2026
Merged

Fix broken code samples in docs content#520
externl merged 1 commit into
icerpc:mainfrom
externl:fix-content-code-samples

Conversation

@externl

@externl externl commented Jul 8, 2026

Copy link
Copy Markdown
Member

Fixes 31 defects in code samples across 19 content pages, found during a full editorial review. Every fix was verified against the 0.6.x branch of icerpc-csharp (examples, templates, and generator sources) — see the verification comment below.

Doesn't compile

  • new ClientConnection("icerpc://…") with a plain string in six samples on the security-with-tls page — no such constructor; wrapped in new Uri(…)
  • ServerAddress = new Uri(…) — the property is ServerAddress?new ServerAddress(new Uri(…))
  • service method taking FeatureCollection instead of IFeatureCollection, plus features.Get<T> missing its call parentheses
  • unterminated interpolated string in the server-address sample
  • if branch with no return in the DI deadline middleware (CS0161)
  • internal static implicit operator — conversion operators must be public (CS0558)
  • missing statement semicolons (invocation-pipeline-with-di ×2, a .proto snippet)

Wrong identifiers

  • greetergreeterProxy, connectionclientConnection, GreeterRequestGreetRequest, WidgetPRoxyWidgetProxy, WellknownTypes/WellKnownTypeWellKnownTypes

Doesn't match the documented mapping / templates

  • dictionary/sequence mapping samples showed bare C# fields; the generator emits required … { get; set; } properties (per fields.md)
  • the Protobuf client tutorial used request without defining it — added the template's var request = new GreetRequest { Name = Environment.UserName };
  • @Widget doc-comment links → {@link Widget}
  • missing public/partial modifiers in two ice-users samples
  • also rewords the sentence attached to the conversion-operator fix ("to be base interface" → "to the base interface's proxy struct")

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings July 8, 2026 14:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the IceRPC documentation to fix a set of compile-breaking and correctness issues in code samples across the Slice, Protobuf, and IceRPC guides, aligning examples with the actual generated C# shapes and public APIs.

Changes:

  • Corrects C# sample code to use the right types/identifiers and valid syntax (e.g., new Uri(...), ServerAddress = new ServerAddress(...), correct proxy names, missing return, missing ;).
  • Aligns Slice language mapping samples with generated output (e.g., required ... { get; set; }, correct WellKnownTypes::* names).
  • Fixes doc-comment cross-references in Slice examples to the established {@link ...} format.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.

Show a summary per file
File Description
content/slice/language-guide/using-proxies-as-slice-types.md Fixes Slice doc-comment links to use {@link Widget} consistently.
content/slice/language-guide/sequence-types.md Updates C# mapping sample to generated required properties.
content/slice/language-guide/result-types.md Fixes WellKnownTypes casing in the mapping table.
content/slice/language-guide/interface.md Fixes proxy typo and corrects conversion operators to public + improves wording.
content/slice/language-guide/fields.md Corrects WellKnownTypes::Uri reference.
content/slice/language-guide/dictionary-types.md Updates C# mapping sample to generated required properties.
content/slice/basics/contract-first.md Fixes incorrect variable usage (greetergreeterProxy).
content/protobuf/language-mapping/service.md Adds missing ; to .proto RPC definition.
content/protobuf/index.md Fixes request message type name (GreetRequest).
content/icerpc/invocation/service-address.md Fixes incorrect invoker variable name (connectionclientConnection).
content/icerpc/dispatch/incoming-request.md Fixes API types/usage (IFeatureCollection, Get<T>()).
content/icerpc/dispatch/dispatch-pipeline.md Fixes ServerAddress sample to use the correct wrapper type.
content/icerpc/dependency-injection/invocation-pipeline-with-di.md Fixes missing semicolons in chained DI examples.
content/icerpc/dependency-injection/dispatch-pipeline-with-di.md Fixes missing return in middleware sample to avoid CS0161.
content/icerpc/connection/server-address.md Fixes unterminated interpolated string / formatting error in sample.
content/icerpc/connection/security-with-tls.md Fixes ClientConnection samples to pass Uri instead of string.
content/icerpc-for-ice-users/ice-definitions/fields.md Aligns record struct samples with expected partial declaration.
content/icerpc-for-ice-users/ice-definitions/enum-types.md Fixes enum sample visibility (public enum).
content/getting-started/icerpc-protobuf-tutorial/client-tutorial.md Adds missing request initialization in the client tutorial sample.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@externl

externl commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

Verified every fix against the 0.6.x branch of icerpc-csharp:

  • new ClientConnection(new Uri(…)) — matches the examples; zero bare-string usages in examples/
  • ServerAddress = new ServerAddress(new Uri(…)) — verbatim in examples/{protobuf,slice}/Thermostat/Device/Program.cs
  • IFeatureCollection features — 42 occurrences in examples; none use concrete FeatureCollection
  • features.Get<T>() is T x — verbatim pattern in examples/{protobuf,slice}/RequestContext/Server/Chatbot.cs
  • var request = new GreetRequest { Name = Environment.UserName }; — verbatim in src/IceRpc.Templates/Templates/IceRpc-Protobuf-Client/Program.cs:35
  • internal required IDictionary<…> X { get; set; } — matches ZeroC.Slice.Generator/StructGenerator.cs:148-152 output
  • public static implicit operator — matches IceRpc.Slice.Generator/ProxyGenerator.cs:146

The remaining fixes (missing semicolons, unterminated string, identifier typos) are syntax-level.

@externl externl requested review from bernardnormier and pepone July 8, 2026 14:45

@pepone pepone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, we should check the horizontal scroll for the updated code samples, possibly for existing ones too.

internal readonly partial record struct RectangleProxy : IRectangle, IProxy
{
internal static implicit operator ShapeProxy(RectangleProxy proxy)
public static implicit operator ShapeProxy(RectangleProxy proxy)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default is now internal isn't it? Is the implicit constructor still public?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversion operator itself is still generated as public static implicit — see ProxyGenerator.cs:146 on the 0.6.x branch. C# requires user-defined conversion operators to be declared public (CS0558 otherwise), even inside an internal type; the member's effective accessibility is then capped by the containing type. So public here matches both the language rule and the generated code, while the proxy struct itself stays internal by default.

@externl externl merged commit 43d281a into icerpc:main Jul 8, 2026
9 checks passed
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.

4 participants