C# / .NET — in 5 Minuten zum ersten Sample
.NET 8 + netstandard2.1, NativeAOT-kompatibel. P/Invoke gegen libzerodds.so. Idiomatic C# (records, async/await, IDisposable). IDL→C#-Codegen via idlc csharp mit Source-Generators für zero-allokierten CDR-Codec.
5-Minuten-Quickstart
libzerodds als Native-Dep, NuGet-Package, ~20 Zeilen C#.
1 · Native-Lib + C#-Binding installieren
ZeroDDS ist auf NuGet — dotnet add package ZeroDDS. Alternativ aus dem Source: Heute geht der C#-Binding-Pfad nur aus Source.
Schritt 1a: libzerodds Runtime holen — pre-built oder Source:
# Ubuntu/Debian
wget https://github.com/zero-objects/zero-dds/releases/download/v1.0.0-rc.3/zerodds-dev_1.0.0-rc.3_amd64.deb
sudo dpkg -i zerodds-dev_1.0.0-rc.3_amd64.deb
# Fedora/RHEL
sudo dnf install https://github.com/zero-objects/zero-dds/releases/download/v1.0.0-rc.3/zerodds-devel-1.0.0-0.rc1.fc40.x86_64.rpm
# Windows: zerodds-1.0.0-x64.msi (Doppelklick oder msiexec /i)
# macOS: brew tap zero-objects/zerodds && brew install zerodds
# Arch: yay -S zerodds-bin
# Docker: docker pull fishermen21/zerodds-cli
# Aus Source (Entwicklung):
git clone https://github.com/zero-objects/zero-dds.git
cd zero-dds && cargo build --release -p zerodds-c-api
Schritt 1b: C#-Binding aus Source (RC3-Plan: dotnet add package ZeroDDS):
cd zero-dds/crates/cs
dotnet pack -c Release
# Resultierendes nupkg lokal als Source nutzen, oder direkt:
# dotnet add reference path/to/zerodds-cs.csproj
2 · Pub/Sub-Roundtrip (Program.cs)
using ZeroDDS;
var factory = DomainParticipantFactory.Instance;
var participant = factory.CreateParticipant(0);
var topic = participant.CreateBytesTopic("Chatter");
var publisher = participant.CreatePublisher();
var subscriber = participant.CreateSubscriber();
using var writer = publisher.CreateBytesWriter(topic);
using var reader = subscriber.CreateBytesReader(topic);
writer.WaitForMatchedSubscription(1, TimeSpan.FromSeconds(5));
reader.WaitForMatchedPublication(1, TimeSpan.FromSeconds(5));
writer.Write("hello"u8.ToArray());
reader.WaitForData(TimeSpan.FromSeconds(3));
foreach (var payload in reader.Take())
{
Console.WriteLine($"got: {System.Text.Encoding.UTF8.GetString(payload)}");
}
▶ Runnable example: csharp-quickstart
3 · Laufen
dotnet run
# got: hello
Installation
Über NuGet
dotnet add package ZeroDDS --prerelease
dotnet add package ZeroDDS.Cdr --prerelease # für IDL-Typen
Über Source
git clone https://github.com/zero-objects/zero-dds.git
cd zero-dds/crates/cs
dotnet build ZeroDDS/ZeroDDS.csproj -c Release
# DLL in target-Verzeichnis
Native-Lib finden
libzerodds.{so,dylib,dll} muss zur Laufzeit auffindbar sein. Drei Optionen:
- System-Install (
/usr/lib/libzerodds.sovia DEB/RPM) LD_LIBRARY_PATH=/path/to/lib dotnet run- Neben das Binary kopieren (
bin/Release/net8.0/libzerodds.so)
Typisierte Topics — idlc csharp
IDL (temperature.idl)
module sensor_msgs {
module msg {
struct Temperature {
long celsius;
string sensor_id;
};
};
};
Codegen + Use
idlc csharp temperature.idl -o Gen/
# erzeugt Gen/SensorMsgs/Msg/Temperature.cs + TypeSupport.cs
# Nutzen
var topic = participant.CreateTypedTopic<Temperature>("Temp");
var writer = publisher.CreateTypedWriter<Temperature>(topic);
writer.Write(new Temperature { Celsius = 23, SensorId = "A7" });
▶ Runnable example: csharp-typed
Der Codec nutzt C#-Source-Generators (ZeroDDS.Cdr.SourceGenerators) — zero-allocation Encode/Decode auf dem Hot-Path.
async/await
await writer.WriteAsync(payload, ct);
await reader.WaitForDataAsync(TimeSpan.FromSeconds(3), ct);
await foreach (var sample in reader.TakeAsync(ct))
{
Console.WriteLine(sample);
}
▶ Runnable example: csharp-async
Cancellation-Token wird durchgereicht; OperationCanceledException beim Cancel.
NativeAOT
Ab .NET 8 voll AOT-kompatibel. PublishAot=true in der .csproj, dotnet publish -c Release. Erzeugt ein single-binary ohne JIT-Runtime — schnelleres Cold-Start, kleineres Image.
<PropertyGroup>
<PublishAot>true</PublishAot>
<TrimMode>link</TrimMode>
</PropertyGroup>
ZeroDDS hat keine Reflection-Calls auf dem Hot-Path; CDR-Codec via Source-Generators ist AOT-friendly.
C# / .NET — first sample in 5 minutes
.NET 8 + netstandard2.1, NativeAOT-compatible. P/Invoke against libzerodds.so. Idiomatic C# (records, async/await, IDisposable). IDL→C# codegen via idlc csharp with source generators for a zero-allocation CDR codec.
5-minute quickstart
libzerodds as a native dep, the NuGet package, ~20 lines of C#.
1 · Install the native lib + C# binding
ZeroDDS is on NuGet — dotnet add package ZeroDDS. Or build from source: Today the C# binding path works only from source.
Step 1a: get the libzerodds runtime — pre-built or source:
# Ubuntu/Debian
wget https://github.com/zero-objects/zero-dds/releases/download/v1.0.0-rc.3/zerodds-dev_1.0.0-rc.3_amd64.deb
sudo dpkg -i zerodds-dev_1.0.0-rc.3_amd64.deb
# Fedora/RHEL
sudo dnf install https://github.com/zero-objects/zero-dds/releases/download/v1.0.0-rc.3/zerodds-devel-1.0.0-0.rc1.fc40.x86_64.rpm
# Windows: zerodds-1.0.0-x64.msi (double-click or msiexec /i)
# macOS: brew tap zero-objects/zerodds && brew install zerodds
# Arch: yay -S zerodds-bin
# Docker: docker pull fishermen21/zerodds-cli
# From source (development):
git clone https://github.com/zero-objects/zero-dds.git
cd zero-dds && cargo build --release -p zerodds-c-api
Step 1b: the C# binding from source (RC3 plan: dotnet add package ZeroDDS):
cd zero-dds/crates/cs
dotnet pack -c Release
# use the resulting nupkg locally as a source, or directly:
# dotnet add reference path/to/zerodds-cs.csproj
2 · Pub/sub roundtrip (Program.cs)
using ZeroDDS;
var factory = DomainParticipantFactory.Instance;
var participant = factory.CreateParticipant(0);
var topic = participant.CreateBytesTopic("Chatter");
var publisher = participant.CreatePublisher();
var subscriber = participant.CreateSubscriber();
using var writer = publisher.CreateBytesWriter(topic);
using var reader = subscriber.CreateBytesReader(topic);
writer.WaitForMatchedSubscription(1, TimeSpan.FromSeconds(5));
reader.WaitForMatchedPublication(1, TimeSpan.FromSeconds(5));
writer.Write("hello"u8.ToArray());
reader.WaitForData(TimeSpan.FromSeconds(3));
foreach (var payload in reader.Take())
{
Console.WriteLine($"got: {System.Text.Encoding.UTF8.GetString(payload)}");
}
▶ Runnable example: csharp-quickstart
3 · Run
dotnet run
# got: hello
Installation
Via NuGet
dotnet add package ZeroDDS --prerelease
dotnet add package ZeroDDS.Cdr --prerelease # for IDL types
Via source
git clone https://github.com/zero-objects/zero-dds.git
cd zero-dds/crates/cs
dotnet build ZeroDDS/ZeroDDS.csproj -c Release
# DLL in the target directory
Finding the native lib
libzerodds.{so,dylib,dll} must be discoverable at runtime. Three options:
- System install (
/usr/lib/libzerodds.sovia DEB/RPM) LD_LIBRARY_PATH=/path/to/lib dotnet run- copy it next to the binary (
bin/Release/net8.0/libzerodds.so)
Typed topics — idlc csharp
IDL (temperature.idl)
module sensor_msgs {
module msg {
struct Temperature {
long celsius;
string sensor_id;
};
};
};
Codegen + use
idlc csharp temperature.idl -o Gen/
# produces Gen/SensorMsgs/Msg/Temperature.cs + TypeSupport.cs
# use it
var topic = participant.CreateTypedTopic<Temperature>("Temp");
var writer = publisher.CreateTypedWriter<Temperature>(topic);
writer.Write(new Temperature { Celsius = 23, SensorId = "A7" });
▶ Runnable example: csharp-typed
The codec uses C# source generators (ZeroDDS.Cdr.SourceGenerators) — zero-allocation encode/decode on the hot path.
async/await
await writer.WriteAsync(payload, ct);
await reader.WaitForDataAsync(TimeSpan.FromSeconds(3), ct);
await foreach (var sample in reader.TakeAsync(ct))
{
Console.WriteLine(sample);
}
▶ Runnable example: csharp-async
The cancellation token is threaded through; OperationCanceledException on cancel.
NativeAOT
Fully AOT-compatible from .NET 8. PublishAot=true in the .csproj, dotnet publish -c Release. Produces a single binary with no JIT runtime — faster cold start, a smaller image.
<PropertyGroup>
<PublishAot>true</PublishAot>
<TrimMode>link</TrimMode>
</PropertyGroup>
ZeroDDS has no reflection calls on the hot path; the CDR codec via source generators is AOT-friendly.