csharp-client

Implements SpacetimeDB client connections, subscriptions, and reducer calls in C# applications.

25.1k|1.1k|Updated Jun 17, 2023
One-click install
npx skills add https://github.com/clockworklabs/SpacetimeDB --skill csharp-client
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-client
Source: https://github.com/clockworklabs/SpacetimeDB/tree/main/codex-plugin/plugins/spacetimedb/skills/csharp-client
Command: npx skills add https://github.com/clockworklabs/SpacetimeDB --skill csharp-client

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires SpacetimeDB.ClientSDK.

What problem does it solve?

Building a .NET client that talks to a SpacetimeDB server requires knowing the SDK's connection builder, event loop, subscription, and callback patterns, which are easy to get wrong without a reference.

Core Features & Use Cases

  • Connection Management: Build authenticated connections with DbConnection.Builder, handle connect, error, and disconnect callbacks, and persist auth tokens.
  • Data Subscriptions & Row Callbacks: Subscribe to all tables or filtered queries, and react to row inserts, updates, and deletes through typed event handlers.
  • Reducer Invocation & Cache Access: Call server reducers, observe their committed or failed status, and query the local client cache by primary key, unique column, or index.
  • Use Case: You are writing a Unity or console .NET game client that must mirror server state in real time; this Skill shows how to wire FrameTick into your loop and subscribe to player tables.

Quick Start

Use the csharp-client skill to write a C# console app that connects to my local SpacetimeDB instance, subscribes to all tables, and prints player rows as they change.

Frequently Asked Questions about csharp-client

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I connect a C# client to SpacetimeDB?

Install the SpacetimeDB.ClientSDK NuGet package and use DbConnection.Builder with WithUri, WithDatabaseName, and WithToken. Register OnConnect, OnConnectError, and OnDisconnect callbacks, then call Build to establish the connection.

How do I subscribe to SpacetimeDB tables in C#?

Use conn.SubscriptionBuilder with an OnApplied callback, then call SubscribeToAllTables or add typed queries via AddQuery with the query builder. Raw SQL strings like SELECT * FROM player are also supported through Subscribe.

Why are my SpacetimeDB C# callbacks not firing?

Callbacks do not fire because FrameTick is not being called. The SDK queues all network messages and only processes them when FrameTick runs on the main thread, so call it every iteration of your application loop.

Can I call SpacetimeDB SDK methods from background threads?

No, the C# SDK is not thread-safe for background use. FrameTick must run on the main thread, and conn.Db cache access from background threads is not supported.

How do I detect reducer failures in the SpacetimeDB C# SDK?

Reducer calls return void, so observe results through reducer callbacks like OnSendMessage. Check ctx.Event.Status for Status.Committed or Status.Failed, which carries the failure reason.