/foundationdb-dotnet-skills:foundationdb-aspirefrom foundationdb-dotnet-skills
Guides through running a FoundationDB cluster and connecting from .NET via Aspire, DI, or direct provider creation. Covers native client loading, version compatibility, and troubleshooting.
Ships in foundationdb-dotnet-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The foundationdb-keys-and-layers, foundationdb-transactions, and foundationdb-advanced-layers skills all start from an IFdbDatabase / IFdbDatabaseProvider you already have. This skill is about getting there: standing up a cluster, loading the native client correctly, and connecting — including the .NET Aspire integration shipped in this repo (FoundationDB.Aspire.Hosting + FoundationDB.Aspire).
IFdbDatabaseProviderApplication code resolves an IFdbDatabaseProvider (then await provider.GetDatabase(ct) or, more commonly, the retry-loop methods). Three ways to create one:
| Way | API | When |
|---|---|---|
| Plain DI | services.AddFoundationDb(apiVersion, opt => …) → IFdbDatabaseProviderBuilder (registers IFdbDatabaseProvider) | a regular host, you supply the cluster file via config |
| No DI | FdbDatabaseProvider.Create(new FdbDatabaseProviderOptions { ApiVersion = 730, … }) | tools/tests/standalone; call provider.Start() |
| Aspire client | builder.AddFoundationDb("fdb", settings, options) | the connection string is injected by an Aspire AppHost (see §3) |
apiVersion selects the client API level and caps the features you can use: 730 ⇒ FoundationDB 7.3 semantics, 740 ⇒ 7.4, 800 ⇒ 8.0. The binding supports 610 up to 740 in 7.4.x, and up to 800 from 8.0; Fdb.GetMaxSafeApiVersion() returns the highest level that both the binding and the loaded native client support. Fdb.DefaultApiVersion is 730, which is why 730 appears in most examples. Pick the level whose semantics you actually rely on, not the newest available: raising it is a behavior change, and it must stay ≤ the highest level of the binding and of the native client (§6). The provider also carries a root FdbPath (a directory-layer partition); everything else resolves relative to it.
Plain-DI / no-DI namespaces: FoundationDB.DependencyInjection. These all still need the native client loaded (§5).
FoundationDB.Aspire.Hosting)On a IDistributedApplicationBuilder (the AppHost), namespace Aspire.Hosting:
// starts a FoundationDB cluster as a Docker container, and emits a connection string named "fdb"
var fdb = builder.AddFoundationDb("fdb",
apiVersion: 730,
root: "/MyApp") // clusterVersion omitted on purpose - see below
.WithLifetime(ContainerLifetime.Persistent); // reuse the container across runs (faster restarts)
builder.AddProject<Projects.MyApp>("app")
.WithReference(fdb) // injects the "fdb" connection string into the app
.WaitFor(fdb); // hold the app until the cluster is healthy
clusterVersion. Left out, the hosting package picks its own last-known-good Docker tag for the major it selects (the FdbAspireHostingExtensions.LatestVersionNN constants, refreshed from Docker Hub by scripts/check-fdb-image-tags.ps1). A tag you hardcode is a number that rots in your AppHost: pin one only when you need a specific image, and then treat it as something to review, alongside rollForward: FdbVersionPolicy.Exact.AddFoundationDb(...) → IResourceBuilder<FdbClusterResource> runs a container.configure new single ssd inside the container (a brand-new cluster has no database until then), and WaitFor(fdb) holds dependents until the database answers. An already-configured database is left untouched. Opt out with .WithAutoProvisioning(false); run mode only.AddFoundationDbCluster(name, apiVersion, root, clusterFile?, clusterVersion?) → IResourceBuilder<FdbConnectionResource> instead connects to an already-running cluster (no container) given a cluster file..WithDataVolume() (name generated from the AppHost and the resource) or .WithDataVolume("name"). The default volume fdb_data is shared by every AppHost on the machine that keeps it: two clusters on it fail with "Unable to lock the file", and a 7.4 server upgrades 7.3 data files in place, beyond the reach of 7.3 servers.FdbVersionPolicy (Exact, etc.) lives in Aspire.Hosting.ApplicationModel. .WithDefaults(timeout, retryLimit, tracing) tunes the connection..WithFdbCli() adds an "FdbCli" command that opens fdbcli inside the container, in the terminal dock. .WithFdbShell() adds an "FdbShell" command that runs the FdbShell .NET tool from NuGet (dotnet tool exec, no package reference) with the cluster's connection string, starting in the root folder; it runs the FdbShell of the same version as the hosting package (released together, so they agree on the --aspire contract), and FdbShell loads the libfdb_c of the cluster's branch from the AppHost's output: the AppHost must reference FoundationDB.Client.Native of the cluster's major.minor (same CPM version as the apps), or WithFdbShell() throws at startup with the fix (also on a branch mismatch). In a solution that holds the FdbShell source, .WithFdbShell<Projects.FdbShell>() runs the project instead (needs a ProjectReference to FdbShell.csproj pinned to the AppHost's TFM with SetTargetFramework). Do not add FdbShell as a project resource: it needs a terminal. Outside the AppHost, fdbshell --aspire / fdbtop --aspire read the same ConnectionStrings__<name> variable, and fail with an actionable error when it is missing.AppHost project setup: Sdk="Aspire.AppHost.Sdk/<ver>"; reference FoundationDB.Aspire.Hosting with IsAspireProjectResource="false" (it's a compile dependency for AddFoundationDb); reference each app project normally (those are launched as resources — their TFM need not match the AppHost).
FoundationDB.Aspire)In the app (not the AppHost), on an IHostApplicationBuilder, namespace Microsoft.Extensions.Hosting:
// reads the "fdb" connection string injected by WithReference(fdb) and registers IFdbDatabaseProvider
builder.AddFoundationDb("fdb",
settings => { /* FdbClientSettings: tracing, health checks, … */ },
options => options.UseNativeClient()); // load libfdb_c (see §5)
The app references FoundationDB.Aspire. The injected connection string looks like ApiVersion=730;Root=/MyApp;ClusterFileContents=…;ClusterVersion=7.4.6 (the ClusterVersion is whatever tag the AppHost resolved, so do not read the one in this example as a recommendation). Standalone (no AppHost), provide the cluster file via configuration instead.
Don't confuse the two
AddFoundationDbs: the AppHost one (IDistributedApplicationBuilder, starts the container) vs the client one (IHostApplicationBuilder, consumes the connection). They have different receivers, so they never collide.
Preferred: the aspire CLI — it provisions the dashboard, OTLP, and ports for you:
dotnet tool install --global aspire.cli # one-time
aspire run --apphost path/to/MyApp.AppHost.csproj
# headless / CI: aspire run --apphost … --detach --non-interactive --format Json
# → returns { appHostPid, dashboardUrl (with login token), logFile }
Fallback: plain dotnet run (or IDE F5) on the AppHost. This requires a Properties/launchSettings.json providing the dashboard + OTLP endpoints, e.g.:
{ "profiles": { "http": { "commandName": "Project",
"applicationUrl": "http://localhost:15200",
"environmentVariables": {
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19200",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20200",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true" } } } }
Without it, a bare dotnet run on the AppHost crashes at startup: "Failed to configure dashboard resource because ASPNETCORE_URLS … was not set / … OTLP endpoint must be provided." The aspire CLI does not need this file.
libfdb_c): where it loads fromThe .NET client talks to the cluster through the native libfdb_c library. Since 7.4.7 the binding loads it from fixed paths only. With the default (FdbDatabaseProviderOptions.NativeLibraryPath left null), it checks, in this order:
runtimes/{rid}/native/ under the application folder, then the application folder itself: where the FoundationDB.Client.Native package deploys the library;%ProgramFiles%\foundationdb\bin\fdb_c.dll (Windows), /usr/lib/libfdb_c.so (Linux), /usr/local/lib/libfdb_c.dylib (macOS).It never searches PATH or LD_LIBRARY_PATH by default: those folders may be writable by other users or programs, and a library planted there would run inside the process. When none of the fixed paths holds the library, opening the database throws DllNotFoundException, and the message lists the paths it checked.
The three ways to provide the library:
FoundationDB.Client.Native with the major.minor of the cluster (8.0.* for an 8.0 cluster, 7.4.* for 7.4, 7.3.* for 7.3; see §6). It ships libfdb_c for linux-arm64, linux-x64, win-x64, osx-arm64 and osx-x64, so the default above finds it with no extra call. options.UseNativeClient() (an extension of that package) pins the load to the package copy only, and reports a missing library with FileNotFoundException while the services are configured, instead of when the database starts.options.UseSystemNativeClient(), or UseNativeClient(allowSystemFallback: true) when the package copy is missing, restores the search of the runtime and the operating system, with the risk above. Use it only on a host you control.services.AddFoundationDb(740, options => options.UseNativeClient()); // package copy only
services.AddFoundationDb(740, options => options.NativeLibraryPath = "/opt/foundationdb/lib/libfdb_c.so"); // explicit path
services.AddFoundationDb(740, options => options.UseSystemNativeClient()); // OS search, with its risk
Without dependency injection, Fdb.Options.SetNativeLibPath(path) sets the path.
Network options (for example the directory of the other client versions of the multi-version client) are set where the provider is registered, and the Aspire configureProvider callback can call it too:
services.AddFoundationDb(740, options => options
.SetNetworkOption(FdbNetworkOption.ExternalClientDirectory, "/opt/foundationdb/clients")
);
They apply in the order of the calls, after the trace and TLS options. The network thread starts once per process, so the options of the first provider that starts apply to the whole process.
Three versions are in play (the .NET binding, the native client library, the cluster), and three rules decide which combinations connect:
FoundationDB.Client.Native (the libfdb_c library) has the same major.minor as the cluster. A 7.3 client cannot talk to a 7.4 cluster, nor a 7.4 client to an 8.0 cluster.apiVersion ≤ the highest level of FoundationDB.Client (740 in 7.4.x, 800 from 8.0).apiVersion ≤ the highest level of the native client (730 for 7.3, 740 for 7.4, 800 for 8.0).The FoundationDB.Client version is independent of the cluster version: it can be newer than the native client (7.4.x binding with a 7.3 client at API 730) or older (7.4.x binding with an 8.0 client at API 740). The Native packages work with FoundationDB.Client 7.4.1 and later. Usually, take the latest FoundationDB.Client, the newest FoundationDB.Client.Native of the cluster's branch, and the highest API level that both support:
| Cluster | FoundationDB.Client | FoundationDB.Client.Native | apiVersion |
|---|---|---|---|
| 7.3.x (not yet upgraded) | latest (7.4.x) | 7.3.* | 730 |
| 7.4.x | latest (7.4.x) | 7.4.* | 740 |
| 8.0.x | latest (7.4.x) | 8.0.* | 740 (800 needs FoundationDB.Client 8.0) |
FoundationDB 8.0 is not yet a stable branch. Choose it only for a new application that will reach production once 8.0 is stable; an existing production cluster stays on 7.4 (or 7.3 until it is upgraded).
<PackageReference Include="FoundationDB.Client" Version="7.4.*" />
<PackageReference Include="FoundationDB.Client.Native" Version="7.3.*" />
services.AddFoundationDb(730, options => options.UseNativeClient()); // 7.4.x binding, 7.3 native client, 7.3 cluster
Upgrading the cluster to another major.minor changes the version of the Native package, then the API level if you want the features of the newer level. The win-x64, osx-arm64 and osx-x64 libraries of every branch (7.3, 7.4 and 8.0) come from the SnowBankSDK/foundationdb-windows-build releases, the Linux ones from the upstream releases.
fdbcli against the cluster reports "One or more processes … incompatible" and "database is unavailable", even though the cluster is internally healthy.clusterVersion (the Docker image tag) match the libfdb_c available to the app. Check the client with fdbcli --version, the server with docker exec <container> fdbcli --version. If you did not pin a tag, the mismatch is almost always a system libfdb_c shadowing the redistributed one (see §5), not the container.apiVersion (e.g. 730) must be ≤ the highest level of the binding and of the native client: rules 2 and 3 above.For talking to multiple cluster versions from one process, FoundationDB's multi-version client loads several external libfdb_c libraries — but the simplest demo/dev setup is: one cluster version, one matching client library.
✅ DO
services.AddFoundationDb(...) / FdbDatabaseProvider.Create(...) otherwise.aspire run; keep a launchSettings.json only as the dotnet run/F5 fallback.FoundationDB.Client version does not take part in this rule. Omitting clusterVersion lets the hosting package pair them for you against the libfdb_c that FoundationDB.Client.Native redistributes; pin it only when you supply your own client library, and then verify both with fdbcli --version.osx-arm64 and osx-x64 (since 7.4.6), so UseNativeClient(allowSystemFallback: false) works; fall back to a system libfdb_c.dylib and allowSystemFallback: true only for an older pin without your RID.⚠️ GOTCHAS
DllNotFoundException: fdb_c ⇒ none of the fixed paths holds the native client; the message lists them. Add FoundationDB.Client.Native with the major.minor of the cluster, or set NativeLibraryPath (see §5). A library only found through PATH or LD_LIBRARY_PATH is no longer loaded by default.dotnet run crash about ASPNETCORE_URLS / OTLP ⇒ missing launchSettings.json, or just use aspire run.AddFoundationDb "ambiguous" / wrong overload ⇒ you imported the wrong namespace; the AppHost call is on IDistributedApplicationBuilder (Aspire.Hosting), the client call on IHostApplicationBuilder (Microsoft.Extensions.Hosting).WithLifetime(ContainerLifetime.Persistent) keeps the cluster's data across runs — handy in dev, but remember to docker rm -f it when you want a clean slate.| What | Where |
|---|---|
| Aspire AppHost integration | FoundationDB.Aspire.Hosting/FdbAspireHostingExtensions.cs (AddFoundationDb, AddFoundationDbCluster, FdbVersionPolicy) |
| Aspire client integration | FoundationDB.Aspire/FdbAspireComponentExtensions.cs (AddFoundationDb), FdbClientSettings.cs |
| Plain DI / no-DI provider | FoundationDB.Client/DependencyInjection/FdbDatabaseServiceCollectionExtensions.cs, Implementation/FdbDatabaseProvider.cs |
| Native client loader | FoundationDB.Client.Native/ (FdbClientNativeExtensions.cs → UseNativeClient; runtimes/ holds the shipped libs) |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
foundationdb, dotnet, aspire, database-connection, native-client
9 skills in this plugin
/crystaljsonHow to use CrystalJson, the custom JSON library in SnowBank.Core (namespace SnowBank.Data.Json). Covers the JsonValue DOM (JsonObject / JsonArray / JsonString / JsonNumber / JsonBoolean / JsonNull / JsonDateTime), the read-only vs mutable model, the CrystalJson static API (Serialize / Parse / Deserialize) and CrystalJsonSettings, the Roslyn source generator for fast reflection-free serializers and read-only/writable proxies ([CrystalJsonConverter] / [CrystalSerializable]), the IJsonSerializable / IJsonPackable / IJsonDeserializable interfaces, MutableJsonValue / ObservableJsonValue and JsonPath. Use whenever code parses, builds, reads, mutates, or serializes JSON with these types, reads optional fields with defaults, declares a generated JSON converter/proxy, or implements custom JSON (de)serialization. Use it even when the request only says "serializer", "converter", or "serialize/deserialize a record, document, or model" without naming JSON: in SnowBank-based code (document stores, sync layers, Layers, models) document and message (de)serialization goes through CrystalJson, not System.Text.Json or Newtonsoft./foundationdb-advanced-layersAdvanced engineering for sophisticated FoundationDB layers with the .NET client (FoundationDB.Client / SnowBank) — the cluster model and transaction lifecycle (proxies, resolvers, tlogs, storage servers, the sequencer/version clock), latency/throughput optimization (batching reads with GetValuesAsync / Task.WhenAll, removing round-trip dependencies, snapshot reads), high-contention avoidance, and distributed patterns (change feeds, version-stamp logs, watch fan-out, version-as-clock leases, retention, fencing/tombstones). Use when building or reviewing a performance-sensitive or distributed layer (a change feed, queue, pub/sub, worker pool, multi-node observable view), tuning transaction latency/throughput, or reasoning about conflicts, the 5-second limit, or cross-node liveness. Builds on the foundationdb-keys-and-layers and foundationdb-transactions skills — read those first.npx claudepluginhub snowbanksdk/foundationdb-dotnet-client --plugin foundationdb-dotnet-skillsOther plugins' skills for the same job