“License cannot be granted” exception when you add a licensed user control to the Windows Form in the same solution
Symptoms
When you create a licensed user control in a project, and then add it to the Windows form in the same solution, you receive the following exception:
An exception occurred while trying to create an instance of ‘Projectname.Controlname’. The exception was “An instance of type ‘Projectname.Controlname’ was being created, and a valid license could not be granted for the type ‘Projectname.Controlname’. Please, contact the manufacturer of the component for more information.”However, when you create a new solution, and then add the licensed user control to the Windows form, the licensed user control is added.
Resolution
Any user control that is implicitly added to the toolbox refers the assembly file in the obj\Debug folder. Therefore, the licensed user control that is created refers to the WindowsControlLibrary1.dll file in the obj\Debug folder. Generally, the license (.lic) files are put in the Bin folder. When you add an instance of a licensed user control to the Windows form in the same solution, the license is validated. Because the .lic file is not located in the obj\Debug folder, you receive the exception.

Leave a Reply