How to license .NET components and controls using Microsoft’s LicenseProvider Class
Microsoft allows software developers to create tools that extend and add functionality to Visual Studio, making developers more productive. If you are a .NET component or control developer, it is important to protect your intellectual property with a method to verify that a developer is authorized to use your product.
With an ordinary application, authorization typically happens when the application is run. In the case of a component or control, an authorization is also needed while the application is still in development and another developer is incorporating your component or control into their project. To help facilitate this, Microsoft provides the System.ComponentModel.LicenseProvider base class.
Two modes of component instantiation
It is important to understand under what conditions, or modes, a control or component may be instantiated, because this is fundamental to how you license it. There are two modes under which a .NET component or control can be instantiated: design time and run time.
- Design time is when the application is being built in the Integrated Development Environment (IDE). When a developer adds a component or control to a project in the IDE, it is instantiated in design time mode.
- Run time is when the compiled application is executed. When an end user or developer runs the application, any controls or components are instantiated in run time mode.
When licensing a control or component, it is generally most important to authorize the license at design time, since this is where your customer (a developer) uses your product. Once that developer distributes their finished application to their own customers, those customers execute the application at run time, and license validation can be bypassed. It is also possible to validate a license at run time if your scenario requires it.
Using the LicenseProvider class
Using the LicenseProvider class is a three step process.
- Apply a LicenseProviderAttribute to your component or control class.
- In your class constructor, call the Validate method of your derived LicenseProvider class. This method runs your licensing code and returns an object derived from the System.ComponentModel.License class.
- When finished, call the Dispose method of the License object returned by the Validate method.
All the important work happens when the LicenseProvider.Validate method is called. You override and customize this method to suit your licensing needs. Inside it, you can check whether the control or component is running at design time or run time:
- If running at run time, you would not validate the license and would allow the component to instantiate normally.
- If running at design time, you would verify the license and only enable the control if the license is authorized, since this is when the developer is actively using your control or component.
How this works with the SoftwareKey System
Combining the LicenseProvider class with the SoftwareKey System lets you support a variety of licensing models for your components and controls, such as time limited evaluations and modular feature activation. Your Validate implementation calls into your PLUS5 (Protection PLUS 5 SDK) licensing logic to confirm the developer is authorized, then enables the component accordingly.
Summary
It is important to protect your intellectual property, whether it is a finished application or a developer control or component. The LicenseProvider class is a powerful tool for managing the licensing requirements that come with distributing a control or component, and it pairs well with the Protection PLUS 5 SDK and SOLO Server to deliver evaluations, feature based licensing, and authorization checks at the right point in the development and deployment lifecycle.