Repository navigation
IceRPC C# 0.7.0
IceRPC C# 0.7.0 is a major release that moves IceRPC to .NET 11 and C# 15, and maps Slice variant enums and Result types to native C# unions.
If you cannot upgrade to .NET 11 yet, stay on IceRPC C# 0.6.x, which targets .NET 10 and remains fully supported.
Slice variant enums and Result now map to C# unions
The headline change in this release is the mapping of Slice variant enums and Result<Success, Failure> to unions, a new language feature introduced in C# 15. Previously, this mapping relied on the Dunet source generator. IceRPC C# 0.7.0 removes this dependency and generates native unions instead.
A Slice variant enum now maps to a C# union with a nested record class for each variant. You process its values using switch expressions and C# pattern matching. The Dunet Match methods are no longer generated.
// Slice
enum Shape {
Square(side: float64)
Circle(radius: float64)
Rectangle(width: float64, height: float64)
}In 0.6.x, you use the Dunet-generated Match method, passing one function per variant in declaration order:
// C#
double area = shape.Match<double>(
square => square.Side * square.Side,
circle => Math.PI * circle.Radius * circle.Radius,
rectangle => rectangle.Width * rectangle.Height);In 0.7.0, you use a switch expression on the C# union:
// C#
double area = shape switch
{
Shape.Square(var side) => side * side,
Shape.Circle(var radius) => Math.PI * radius * radius,
Shape.Rectangle(var width, var height) => width * height,
};Result<TSuccess, TFailure> is now a C# union whose two cases are Success<TSuccess> and Failure<TFailure>, two new record classes in the ZeroC.Slice namespace. You construct a result from one of these cases, which converts implicitly to the result, and use pattern matching to process it:
// Server side
Result<string, GreeterError> result = name switch
{
"" => new Failure<GreeterError>(new GreeterError.EmptyName()),
_ when name.Length > MaxLength => new Failure<GreeterError>(new GreeterError.NameTooLong(MaxLength)),
_ => Result.FromSuccess($"Hello, {name}!"),
};
// Client side
string message = result switch
{
Success<string>(var greeting) => greeting,
Failure<GreeterError>(var error) => $"Error: {error}",
};Both variant enums and Result are now value types rather than reference types. Their Slice encoding remains unchanged.
See the DiscriminatedUnion and CustomError examples for complete code.
Upgrade notes and breaking changes
IceRPC C# 0.7.0 requires .NET 11 and introduces several breaking changes:
- .NET 11: IceRPC for C# now targets .NET 11 and is compiled with C# 15.
- Variant enums and Result: The Dunet
Matchmethods are gone. Variant enums andResultare now value types, so optional values use nullable value types. ATSuccessorTFailurevalue no longer converts implicitly to aResult; wrap it inSuccess<TSuccess>orFailure<TFailure>instead. Update your code as shown above. - ServiceAddress:
ServiceAddressis now a union withIceandIceRpcvariants. Each variant exposes only the properties applicable to its protocol. - WellKnownTypes::Uuid encoding: UUIDs are now encoded in the network byte order specified by RFC 9562, instead of the mixed-endian layout used by .NET's
Guid. IceRPC 0.7.0 and 0.6.x peers cannot exchange UUID values correctly. Take this incompatibility into account when upgrading clients and servers. - Telemetry tags: The telemetry interceptor and middleware now follow the stable OpenTelemetry semantic conventions for RPC spans. The
rpc.systemtag is renamedrpc.system.name, andicerpc.pathreplacesrpc.service. Update any trace queries and dashboards that use the old tag names. - Slice MSBuild items: The
SliceFileitem type is renamedSliceSource, andSliceDirectoryis renamedSliceReference. Update your project files accordingly. In particular,SliceFileitems are now ignored.
Other notable changes
.NET
- The IceRPC assemblies now use Runtime Async, a .NET 11 feature that replaces compiler-generated async state machines with runtime-managed async execution.
Core
- An interceptor or middleware can process the payload of an outgoing request or response just before it is sent, by installing a payload writer interceptor with the
Usemethod ofOutgoingRequestorOutgoingResponse. The new StreamTransformWriter class implements such an interceptor with aStreamtransform: you give it a function that wraps a stream, such asstream => new CryptoStream(stream, ...), and it transforms the payload as it is written. The compressor interceptor and middleware use this class to compress payloads withBrotliStreamandDeflateStream.
Protobuf
- Added the
Accessmetadata toProtoFileitems. Setting it tointernalmakes all code generated from the Proto file internal, including messages, IceRPC services, and clients. The default remainspublic.
Interceptors and middleware
- The telemetry interceptor and middleware now record the peer's IP address and port in the
network.peer.addressandnetwork.peer.porttags. They also make therpc.system.name,rpc.method, andicerpc.pathtags available to samplers. - The telemetry middleware now samples dispatch activities using their remote parent, allowing parent-based samplers, including the OpenTelemetry default, to follow the caller's sampling decision.
- The compressor interceptor and middleware now produce smaller Brotli output for payloads larger than a few KB when using the default compression level.
- The retry interceptor no longer retries a request against another server address after receiving a
NotFoundresponse over the Ice protocol. ANotFoundresponse is now final for both protocols.
Templates
- Protobuf project templates now generate internal code from their Proto files by default. You can change this behavior using the
Accessmetadata on theProtoFileitem.
Full changelog
All pull requests merged for this release:
https://github.com/icerpc/icerpc-csharp/pulls?q=is%3Apr+is%3Amerged+milestone%3A0.7.0