How to license .NET components and controls using Microsoft’s LicenseProvider Class

By Dan H.  |  Software Licensing Tips

Posted:  December 20

Microsoft allows software developers to create tools which extend and add functionality to Visual Studio, making software 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 would happen when the application is run, but in the case of a component or control, an authorization is also needed when the application is in the process of development and a developer is incorporating your component or control.  To help facilitate this, Microsoft has created 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, as this is fundamental for its licensing.  There are two modes under which a .NET component/control may be instantiated: design time and run time.

  • Design time is when the application is being developed in the Integrated Development Environment (IDE).  When a component or control is added to a project in the IDE by a developer, 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 more important to authorize the license in design time as this is where your customer, a developer, will be using your product.  Once the developer distributes their application to their customers, these customers will execute the application in run time. License validation should be bypassed,  although it is certainly possible to also validate a license for the run time case.

Using the LicenseProvider Class

It is a three step process to use the LicenseProvider class.

  1. LicenseProviderAttibute will need to be applied to your component or control class.
  2. In your class constructor, call the Validate method of your derived LicenseProvider class. This is the method that will execute your licensing code and return an object derived from the System.ComponentModel.License class.
  3. When finished, call the Dispose method of the License object returned by the Validate method.

All the important things happen when the LicenseProvider.Validate method is called, and this method is overridden and customized to suit your licensing needs.  In this method you may check if the control or component is running in design time or run time. If in run time, you would not validate the license and allow the component to instantiate normally.  Conversely, if running in design time, you would verify the license and only enable the control if the license is authorized, as this is when the developer will be using your control or component.

Conclusion

It is important to protect your intellectual property, whether it be an application or a developer control or component.  The LicenseProvider class can be a powerful tool to better manage the licensing requirements imposed by your control or component.  Combining this class with the SoftwareKey System allows for a variety of licensing solutions, such as evaluations and modular features.  If you’d like more guidance on control and component licensing, rest assured the SoftwareKey team is always just a click or a call away.

About the Author

Dan is a software engineer at SoftwareKey with extensive experience in licensing technology and additional experience in video and audio development.

Dan H.


Tags


Related Posts

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>