Link License File

◷ Reading Time: 2 minutes

Loading License

In Version 8, there are three ways of linking and loading the license:

  1. Using LicenseProvider attribute in assembly
  2. Using UserLicense.Initialize(YourLicenseProviderType) method call
  3. Using UserLicense.Key property set (ver 8.0.150+)

LicenseProvider in Assembly

In your assembly set below attribute.

[assembly: LicenseProvider(typeof(FileBasedLicenseProvider))]

Runtime will look for flexrule.license.lic file in the Environment.CurrentDirectory to load the license file automatically.

Using Key Property

Simply set the property of Key in your application as below:

UserLicense.Key = File.ReadAllText("flexrule.license.lic");       // make sure the license file is side by side of the executable

Using Initialize method

License key can be provided by implementing your own ILicenseProvider type and applying it by calling UserLicense.Initialise(YourLicenseProviderType).

public class MyLicense : ILicenseProvider
{
    public string ReadLicense()
    {
        // make sure the license file is side by side of the executable 
        return File.ReadAllText("flexrule.license.lic");
    }
}

make sure the license file is side by side of the executable. Or you can simply embed the license content in the application or read it from other locations i.e. database.

Load License

After you have the type that loads the license, simply use UserLicense.Initialize to initialize your license, on application load.

For example below shows how to initialize the license in a WPF application.

public partial class App : Application
{
    public App()
    {
        UserLicense.Initialize(new MyLicense());
    }
}
Updated on July 23, 2019

Was this article helpful?

Related Articles