.NET SDK Reference

Updated 1 week ago by Archana Singh

This topic explains how to use the Harness Feature Flags (FF) SDK in your .NET application. You can use .NET Server SDK or .NET Core Server SDK. The following table lists the details of both versions:

.NET Server SDK

.NET Core Server SDK

Requires 4.8 version of .NET framework

Requires 3.1 version of .NET core framework

.NET Server SDK GitHub repository

.NET Core Server SDK GitHub repository

.NET Server Sample Application

.NET Core Server Sample Application

In this topic:

Before You Begin


  1. Create a feature flag in Harness Feature Flags. Feature flags wrap your code and allow you to manage the feature release in a controlled way. See Create a Feature Flag.
  2. Ensure that you have created your SDK Key. See Create an SDK Key.
  3. A .NET application to test your feature flag. If you do not have your .NET Application, you can download a sample application from the GitHub repository. See .NET Server Sample Application and .NET Core Server Sample Application.
    1. On the GitHub page, click Code and then clone the sample application. For more information, see Cloning a repository.
    2. Import your project in an IDE such as Visual Studio Code.

Use Harness Feature Flags SDKs with .NET Applications

Perform the following steps to get started with using the Feature Flags SDK in your .NET application:

Step 1: Install the FF SDK Dependency

The first step is to install the FF SDK as a dependency in your application using your application's dependency manager. You can use Package Manager, .NET CLI, PackageReference, etc. for your application. Refer to the following packages to identify the latest version for your build automation tool:

This document uses.NET CLI and uses 1.0.1 version for .NET Server SDKs:

dotnet add package ff-netF48-server-sdk --version 1.0.1

This document uses.NET CLI and uses 1.0.0 version for .NET Core Server SDKs:

dotnet add package ff-net31-Server-SDK --version 1.0.0

Step 2: Authorize your Application to Connect to the FF Client

After installing the SDK, enter the SDK keys that you created for your environment. The SDK keys authorize your application to connect to the FF client.

target represents the desired target for which you want the features to be evaluated.

"YOUR_API_KEY" is an authentication key. See Create an SDK Key.

* Put the API Key here from your environment

config = Config.Builder()

CfClient cfClient = await CfClient.getInstance(API_KEY, config);

* Define you target on which you would like to evaluate
* the featureFlag
io.harness.cfsdk.client.dto.Target target =
.Name("User1") //can change with your target name
.Identifier("user1@example.com") //can change with your target identifier

This initializes the SDK.

Step 3: Evaluate Target for Your Feature Flag

Once you have added the target, evaluate the target for your feature flag. A feature flag is evaluated for a particular target.

Bool Variation

boolean result = await cfClient.boolVariation("sample_boolean_flag", target, false);  
Number Variation

double result =  awaitcfClient.numberVariation("sample_number_flag", target, 0);  
String Variation

string result = await cfClient.stringVariation("sample_string_flag", target, "");  

Step 4: Verify Your Feature Flag

Run the application from your IDE and verify whether the flag variation value displayed on your application page is consistent with the feature flag you created.

Toggle the flag on and off to verify if your application is getting updated.

Use Feature Flags Metrics

Metrics API endpoint can be changed as the following:


Otherwise, the default metrics endpoint URL is used.

Public API Methods

The Public API exposes a few methods that you can utilize:

public async Task<bool> boolVariation(string key, dto.Target target, bool defaultValue)

public async Task<string> stringVariation(string key, dto.Target target, string defaultValue)

public async Task<double> numberVariation(string key, dto.Target target, int defaultValue)

public async Task<JObject> jsonVariation(string key, dto.Target target, JObject defaultValue)

Please Provide Feedback