No results for ""
  • Home
  • API docs


.NET SDK reference (client-side)

Read time: 6 minutes
Last edited: May 09, 2024
Recent major versions

Version 5 of the .NET (client-side) SDK introduces support for .NET 7 and MAUI, and drops support for Xamarin. To learn more about upgrading, read .NET (client-side) SDK 4.x to 5.0 migration guide.

Version 4 of the .NET (client-side) SDK introduces optional automatic collection of environment attributes. To learn more about upgrading, read .NET (client-side) SDK 3.x to 4.0 migration guide.

Version 3 of the .NET (client-side) SDK replaces users with contexts. A context is a generalized way of referring to the people, services, machines, or other resources that encounter feature flags in your product. Contexts replace another data object in LaunchDarkly: "users." To learn more about upgrading, read .NET (client-side) SDK 2.x to 3.0 migration guide and Best practices for upgrading users to contexts.

Code samples on this page are from the several most recent SDK versions where they differ.


This topic documents how to get started with the client-side .NET SDK, and links to reference information on all of the supported features.

SDK quick links

LaunchDarkly's SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and sample applications:

SDK API documentationSDK API docs
GitHub repositorydotnet-client-sdk
Sample applications.NET (client-side)
Published moduleNuGet
For use in mobile, desktop, and embedded client applications only

This SDK is intended for use in single-user mobile, desktop, and embedded applications. If you have a .NET application and want to set up LaunchDarkly on the server-side, read the server-side .NET SDK reference.

To learn more about LaunchDarkly's different SDK types, read Client-side, server-side, and edge SDKs.

Get started

After you complete the Get started process, follow these instructions to start using the LaunchDarkly SDK in your application.

SDK version compatibility

Starting with version 5, the .NET (client-side) SDK supports Microsoft's .NET 7 and MAUI.

The LaunchDarkly .NET (client-side) SDK is compatible with Android version 5.0 and higher and with iOS version 11.0 and higher. It is also compatible with any other platform that supports .NET Standard version 2.0 or higher, although the .NET Standard version lacks some mobile-specific features such as detecting network connectivity.

If you use Xamarin, you cannot use version 5 of the LaunchDarkly .NET (client-side) SDK. You must migrate to MAUI to continue using the LaunchDarkly SDK. To learn more about migrating, read Microsoft's documentation on how to Upgrade from Xamarin to .NET.

Install the SDK

To start using the client-side .NET SDK:

Install-Package LaunchDarkly.ClientSdk

Next, import the LaunchDarkly packages in your application code:

using LaunchDarkly.Sdk;
using LaunchDarkly.Sdk.Client;
// LaunchDarkly.Sdk defines general types like Context, which are also used in the server-side .NET SDK.
// LaunchDarkly.Sdk.Client defines the LdClient and Configuration types for the client-side .NET SDK.

Initialize the client

The .NET (client-side) SDK uses a mobile key

The .NET (client-side) SDK uses a mobile key. Your environment's mobile key is available in the Projects tab of your Account settings page. To learn more about key types, read Keys.

After you install the dependency, initialize the LaunchDarkly client by creating a single, shared instance of LdClient. To create a client instance, you need your environment's mobile key. This authorizes your application to connect to a particular environment within LaunchDarkly.

Never embed a server-side SDK key into a client-side application

Mobile keys are not secret and you can expose them in your client-side code without risk. However, never embed a server-side SDK key into a client-side application.

You can block for a short period of time until the SDK retrieves the latest feature flags from LaunchDarkly using a timeout parameter. If you use a timeout parameter, do not set it for more than five seconds.

Always include a timeout parameter

Do not configure your SDK to initialize without a timeout parameter. Doing so will cause your app never to load if there is a connectivity problem. We recommend setting a timeout for no more than 1-5 seconds.

Here's how:

var context = Context.New("context-key-123abc");
var timeSpan = TimeSpan.FromSeconds(5);
client = LdClient.Init("mobile-key-123abc", ConfigurationBuilder.AutoEnvAttributes.Enabled, context, timeSpan);

You can also initialize the SDK asynchronously. However, we do not recommend initializing the SDK asynchronously because it does not have a timeout option. Initializing without a timeout option will cause your app never to load if there is a connectivity problem.

To initialize asynchronously:

Context context = Context.New("context-key-123abc");
client = await LdClient.InitAsync("mobile-key-123abc", ConfigurationBuilder.AutoEnvAttributes.Enabled, context);

For a complete list of the specific LdClient configuration options available in this SDK, read Configuration.

LdClient must be a singleton

It's important to make LdClient a singleton for each LaunchDarkly project. The client instance maintains internal state that allows LaunchDarkly to serve feature flags without making any remote requests. Do not instantiate a new client with every request.

If you have multiple LaunchDarkly projects, you can create one LDClient for each. In this situation, the clients operate independently. For example, they do not share a single connection to LaunchDarkly.

Android requires AccessNetworkState permission

Android requires the AccessNetworkState permission and you must configure it in the Android project. To learn more about how to implement this requirement, read Microsoft's MAUI Connectivity documentation.

Evaluate a context

After you create the client, you can use it to check which variation a particular context will receive for a given feature flag.

To evaluate a context:

bool showFeature = client.BoolVariation("flag-key-123abc", false);
if (showFeature) {
// Application code to show the feature
else {
// The code to run if the feature is off
Making feature flags available to this SDK

You must make feature flags available to mobile SDKs before the SDK can evaluate those flags. If an SDK tries to evaluate a feature flag that is not available, the context will receive the fallback value for that flag.

To make a flag available to this SDK, check the SDKs using Mobile key checkbox during flag creation, or on the flag's Settings tab. To make all of a project's flags available to this SDK by default, check the SDKs using Mobile key checkbox in your project Settings.

Using the Relay Proxy

You can configure the client-side .NET SDK to connect to the Relay Proxy as follows:

var config = Configuration
.Builder("mobile-key-123abc", AutoEnvAttributes.Enabled)
LdClient client = LdClient.Init(config);

Shut down the client

Shut down the client when your application terminates. To learn more, read Shutting down.

Data collection

To learn more about data collection within this SDK and implications on submissions to the Apple App Store, read the Apple App Store data collection policy.

Supported features

This SDK supports the following features: