This tutorial shows how to get started with the LEADTOOLS SDK in a C# .NET 6 application.
|Summary||This tutorial covers how to set a license in a C# .NET 6 console application.|
|Completion Time||30 minutes|
|Visual Studio Project||Download tutorial project (1 KB)|
|Platform||C# .NET 6 Console Application|
|IDE||Visual Studio 2022|
|Runtime Target||.NET 6 or higher|
|Runtime License||Download LEADTOOLS|
|Try it in another language||
Before any functionality from the SDK can be leveraged, a valid runtime license will have to be set.
For instructions on how to obtain a runtime license refer to Obtaining a License.
Launch Visual Studio and select Create a new project.
Select Console App (.NET) and click Next.
Add the project name and specify the location where the project to be saved to and click Next.
Select the framework version, in this case we will be using .NET 6.0, and click Create.
To add the LEADTOOLS references in this tutorial, add a LEADTOOLS NuGet package since this will be using .NET.
Right-click on the C# project in the Solution Explorer and select Manage NuGet Packages...
Browse for LEADTOOLS, then select any of the LEADTOOLS NuGet packages and install it. You will need to accept LEAD's End User License Agreement.
Now that the LEADTOOLS references have been added to the project, add the relevant code to set your license.
Program.cs in the Solution Explorer, then add
using Leadtools; to the using block at the top.
Program class add a new method called
InitLEAD() and call it in the
Main method. Add the below code to properly set the LEADTOOLS native runtimes and your license.
static void Main(string args)
static void InitLEAD()
var leadSdkBase = @"C:\LEADTOOLS22\";
var nativeRuntimes = Path.Combine(leadSdkBase, @"Bin\CDLL\x64\");
var licenseDir = Path.Combine(leadSdkBase, @"Support\Common\License\");
// Set the library path to the native runtime location
Platform.LibraryPath = nativeRuntimes;
// Set the LEADTOOLS License
RasterSupport.SetLicense(licenseDir + "LEADTOOLS.LIC", File.ReadAllText(licenseDir + "LEADTOOLS.LIC.KEY"));
Console.WriteLine("License file invalid or expired.");
Console.WriteLine("License file set successfully.");
When using LEADTOOLS with .NET 6+, you need to set the native runtimes using the
The project can then be built and run through Visual Studio or the command line provided the deployment environment has .NET supported and installed. To install .NET, refer to the installation guide on Microsoft's documentation site.
Run the project by pressing F5, or by selecting Debug -> Start Debugging.
If the steps were followed correctly, a message will appear in the console showing
License file set successfully.
Open the terminal and browse to the project directory. Then execute
dotnet build to build the project and
dotnet run to execute it. Other commands include
dotnet rebuild, and
This tutorial covered how to create a new C# .NET Project, how to add references via NuGet, and how to execute the project on Windows, Mac and Linux.
This is the basis for all C# .NET applications leveraging the LEADTOOLS SDK. All functionality in the SDK is unlocked via setting a license. The
SetLicense method must be called before calling any other LEADTOOLS SDK functions.
Once the SDK is purchased, the evaluation license can be replaced with a valid runtime license to disable the Nag Message.