How to: License Components and Controls

The .NET Framework provides a licensing model that is identical for all components and controls, including Windows Forms controls and ASP.NET server controls, and is fully compatible with licensing for Microsoft ActiveX® controls.

With licensing, you, as the component or control author, can help protect your intellectual property by verifying that a developer is authorized to use your component or control. This verification is more important at design time, when a developer incorporates your component or control into an application, than at run time. When a developer legally uses your licensed component or control at design time, the developer's application gets a run-time license that the developer can freely distribute.

You have many other levels of licensing support with the licensing model. The model separates the validation logic from the component or control. A license provider grants licenses and performs the validation logic. The provider is a class that derives from System.ComponentModel::LicenseProvider. The steps that you must take to enable licensing are straightforward.

When you use the default implementation of LicenseProvider provided by LicFileLicenseProvider, the license file is formatted in the following manner:

  • The name of the file must be the fully qualified name, including the namespace, of the class with the file name extension .LIC. For example:


  • The content of the license file should contain the following text string:

    "myClassName is a licensed component."

    myClassName is the fully qualified name of the class. For example:

    "Namespace1.Class1 is a licensed component."

The following code examples show a Windows Forms control and an ASP.NET server control that implement a simple case of licensing.

To enable licensing for your component or control

  1. Apply a LicenseProviderAttribute to the class.

  2. Call Validate or IsValid in the constructor.

  3. Call Dispose on any granted license in the finalizer of the class or before the finalizer is called.

The following code examples use the built-in license provider class LicFileLicenseProvider, which enables you to use text license files and mimics the behavior of COM (ActiveX) licensing. More complex licensing scenarios, such as calling an XML Web service to limit the number of instances of a component, require different kinds of license providers.

// Adds the LicenseProviderAttribute to the control.

public ref class MyControl: public Control
   // Creates a new, null license. 
   License^ license;


      // Adds Validate to the control's constructor.
      license = LicenseManager::Validate( MyControl::typeid, this );

      // Insert code to perform other instance creation tasks here.

      if ( license != nullptr )
         delete license;
         license = nullptr;
No code example is currently available or this language may not be supported.