Skip to content

0.7.0

Latest

Choose a tag to compare

@pepone pepone released this 20 Nov 19:19
· 19 commits to main since this release
e151a04

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 Match methods are gone. Variant enums and Result are now value types, so optional values use nullable value types. A TSuccess or TFailure value no longer converts implicitly to a Result; wrap it in Success<TSuccess> or Failure<TFailure> instead. Update your code as shown above.
  • ServiceAddress: ServiceAddress is now a union with Ice and IceRpc variants. 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.system tag is renamed rpc.system.name, and icerpc.path replaces rpc.service. Update any trace queries and dashboards that use the old tag names.
  • Slice MSBuild items: The SliceFile item type is renamed SliceSource, and SliceDirectory is renamed SliceReference. Update your project files accordingly. In particular, SliceFile items 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 Use method of OutgoingRequest or OutgoingResponse. The new StreamTransformWriter class implements such an interceptor with a Stream transform: you give it a function that wraps a stream, such as stream => new CryptoStream(stream, ...), and it transforms the payload as it is written. The compressor interceptor and middleware use this class to compress payloads with BrotliStream and DeflateStream.

Protobuf

  • Added the Access metadata to ProtoFile items. Setting it to internal makes all code generated from the Proto file internal, including messages, IceRPC services, and clients. The default remains public.

Interceptors and middleware

  • The telemetry interceptor and middleware now record the peer's IP address and port in the network.peer.address and network.peer.port tags. They also make the rpc.system.name, rpc.method, and icerpc.path tags 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 NotFound response over the Ice protocol. A NotFound response 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 Access metadata on the ProtoFile item.

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