Skip to content

.NET, MAUI, Xamarin, Mono and Unity client library SDK for Ably realtime messaging service

License

Notifications You must be signed in to change notification settings

ably/ably-dotnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Repository files navigation

Ably Pub/Sub Dotnet HeaderNuGet versionLicense

Ably Pub/Sub .NET SDK

Build any realtime experience using Ably’s Pub/Sub .NET SDK. Supported on all popular platforms and frameworks, including Unity and MAUI.

Ably Pub/Sub provides flexible APIs that deliver features such as pub-sub messaging, message history, presence, and push notifications. Utilizing Ably’s realtime messaging platform, applications benefit from its highly performant, reliable, and scalable infrastructure.

Find out more:


Getting started

Everything you need to get started with Ably:


Supported platforms

PlatformSupport
.NET Standard2.0+
.NET6.0+, .NET Core 2.0+
.NET Framework4.6.2+
Mono5.4+
Xamarin.Android8.0+
Xamarin.iOS10.14+
Xamarin.Mac3.8+
Unity2019.x+
MAUI.NET 6.0+

Important

SDK versions < 1.2.12 will be deprecated from November 1, 2025.


Installation

The SDK is available as a nuget package. To get started with your project, install the package from the Package Manager Console or the .NET CLI.

Package Manager Console:

PM> Install-Package ably.io

.NET CLI in your project directory:

dotnet add package ably.io

MAUI configuration

When using Ably in a MAUI project, be aware of potential issues caused by assembly trimming, as ably-dotnet relies on the reflection API.

Add the following to your .csproj file to prevent trimming of the IO.Ably assembly:

<ItemGroup> <TrimmerRootAssemblyInclude="IO.Ably" /> </ItemGroup>

Usage

The following code connects to Ably's realtime messaging service, subscribes to a channel to receive messages, and publishes a test message to that same channel:

// Initialize Ably Realtime clientvarrealtime=newAblyRealtime("your-ably-api-key");// Wait for connection to be establishedrealtime.Connection.On(ConnectionEvent.Connected, args =>{Console.WriteLine("Connected to Ably");});// Get a reference to the 'test' channelIRealtimeChannelchannel=realtime.Channels.Get("test");// Subscribe to all messages published to this channelchannel.Subscribe(message =>{Console.WriteLine($"Received message: {message.Data}");});// Publish a test message to the channelawaitchannel.PublishAsync("test-event","Hello World!");

Enable logging using a new class that implements ILoggerSink interface.

classCustomLogHandler:ILoggerSink{publicvoidLogEvent(LogLevellevel,stringmessage){Console.WriteLine($"Handler LogLevel : {level}, Data :{message}");}}

Update clientOptions for LogLevel and LogHandler.

clientOpts.LogLevel=LogLevel.Debug;clientOpts.LogHandler=newCustomLogHandler();

Unity usage

Releases

The CHANGELOG.md contains details of the latest releases for this SDK. You can also view all Ably releases on changelog.ably.com.


Contributing

Read the CONTRIBUTING.md guidelines to contribute to Ably.


Support, feedback and troubleshooting

For help or technical support, visit Ably's support page or GitHub Issues for community-reported bugs and discussions.

Increasing transport send and receive buffers for .NET framework

In high-throughput scenarios, for example, sending messages >50KB, the default WebSocket buffer in the .NET Framework can cause instability or errors. This issue is discussed in GitHub issue #446.

To mitigate this, increase the WebSocket buffer size to the maximum allowed (64KB):

varmaxBufferSize=64*1024;varoptions=newClientOptions();varwebsocketOptions=newMsWebSocketOptions{SendBufferInBytes=maxBufferSize,ReceiveBufferInBytes=maxBufferSize};options.TransportFactory=newMsWebSocketTransport.TransportFactory(websocketOptions);varrealtime=newAblyRealtime(options);