Skip to main content Skip to footer

Licensing of .NET Components

Recently I received a question from our Sales department about using Spread for Windows Forms inside a UserControl and compiling it to a control library (DLL). There was some confusion about whether this is supported, because the customer was getting license errors when trying to use the UserControl inside a Windows Form EXE. This post is intended to clarify how .NET component licensing works.

In .NET, a component (whether it is a System.ComponentModel.Component or System.Windows.Forms.Control) is either a licensed component or an unlicensed component. This is determined by whether it has the System.ComponentModel.LicenseProviderAttribute attribute on the component. By default, when you create a class library or control library project in Visual Studio, the class or control is not licensed. You must add the LicenseProvider attribute to the code in order to make it a licensed component:

VB:

<System.ComponentModel.LicenseProvider(GetType(System.ComponentModel.LicenseProvider))>

C#:

[System.ComponentModel.LicenseProvider(typeof(System.ComponentModel.LicenseProvider))]

Spread for Windows Forms is a licensed component. Licensed components cause Visual Studio to call into the LicenseProvider specified by the attribute to check for whether the component is licensed on the machine where it is being used. When the component is added to a form in design time, Visual Studio checks whether the control is licensed for use in design mode. It requests a design time license for the component, and if it is able to get one, it adds a reference to the component's type to the .LICX file for the project:

FarPoint.Win.Spread.FpSpread, FarPoint.Win.Spread, Version=5.0.3503.2008, Culture=neutral, PublicKeyToken=327c3516b1b18457

Then when the project is built, Visual Studio use the license compiler (LC.EXE) to compile the .LICX file into a .LICENSES file that gets embedded into the assembly as a resource. The license compiler gets back a string value from the component, and that string value is what gets built into the resources for the assembly. When the control is created at run time, the LicenseProvider is called to request a run time license. It passes that string value back into the LicenseProvider, and if it gets back a license, then the component creates successfully.

If you create a UserControl library project (DLL) and embed a Spread control inside the UserControl, then your UserControl will require a design time license (development license) for Spread in order to be used in design time. As long as the machine on which the UserControl project is being created is licensed for development with Spread, it will work to create such a project. The licensing works the same in a UserControl library project as I described above: it checks the LicenseProvider, tries to get the design time license for Spread, and adds the Spread's type to the .LICX for the project.

However, if you do not make the UserControl a licensed component, then when that control is used in design time on a form in a Windows Forms EXE project, Visual Studio will not go through that process for the UserControl since it is not licensed. It will not automatically create a .LICX or add the UserControl's type. But, since the UserControl is being used in design time, and it contains a Spread control, it will do the design time license check for the Spread control, and putting the UserControl on the form will fail if the machine is not licensed for development with Spread. Since there is no .LICX created, when the project is run, it will fail because there is no embedded string to verify to get the run time license for creating the Spread control.

You can manually add the .LICX to the project and/or manually add the entry for the Spread's type, and it will work in the run-time case, but it still will not work in the design time case unless the machine is licensed for development with Spread.

If you make the UserControl licensed, then Visual Studio will go through the same process described above, and create the .LICX with a reference to the UserControl's type. Then when the project is built, it will compile the .LICX as described above, and the EXE will get both the UserControl's and the Spread's license strings embedded in the resources, and it will work to create the form and UserControl and embedded Spread control at run time.

Whether the UserControl is licensed or not, you will still need to be licensed to use Spread in design time in order to use the UserControl in design time, if it contains an embedded Spread control.

MESCIUS inc.

comments powered by Disqus