Skip to main content Skip to footer

Licensing Spread Inside a UserControl

In .NET, a component/control can be licensed or unlicensed depending on whether it has the System.ComponentModel.LicenseProvide attribute. Spread for Windows is also a licensed component as it has LicenseProvider attribute added to it. First lets discuss about unlicensed UserControl. When we use an unlicensed UserControl containing Spread on a Windows Forms at design time, Visual Studio checks whether Spread is licensed to be used at design time but it does not check for the UserControl as it is an unlicensed component. When no license is found on the machine for Spread so that it can be used at design time, creation of Spread fails both at design time and at run time for the project. This blog will guide on how we can license Spread when we use it in a licensed user control. By default, when we create a class library or control library project in Visual Studio, the class or control is not licensed. We must add the LicenseProvider attribute to the code in order to make it a licensed component e.g. VB:

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

C#:

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

Visual Studio plays an important role here as it calls the LicenseProvider attribute for the component to check whether it is licensed on the machine where it is being used. At design time Visual Studio checks whether this component is licensed to be used at design time too. If Visual Studio find the license information for the component successfully it adds a licenses.licx file to project with Spread’s entries something like: FarPoint.Win.Spread.FpSpread, FarPoint.Win.Spread, Version=6.0.3506.2008, Culture=neutral, PublicKeyToken=327c3516b1b18457 You may also add this licenses.licx file manually to run the project however the machine should be licensed to use Spread at design time. At compile time Visual Studio with the license compiler(LC.Exe) compiles licenses.licx file into a .Licenses file. This .Licenses file gets embedded into the assembly as a resource. License compiler gets a string value from the component which gets embedded into the resources for the assembly. During Runtime, LicenseProvider is called toverify the license information (string value returned by license compiler). On successful verification component is created at run time. Lets discuss what happens when spread is used inside a UserControl. You need to remember that Spread always require license in order to be used at design time whether you use it inside a UserControl or alone. For Spread used inside an UserControl, Runtime Licensing process remains same as discussed above. It uses .LICX file to embed the license information for run time using license compiler. 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 UserControl and embedded Spread control at run time.

MESCIUS inc.

comments powered by Disqus