Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Command Bars
  New Posts New Posts RSS Feed - LicenseException in C#.Net
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

LicenseException in C#.Net

 Post Reply Post Reply
Author
Message
Boyd View Drop Down
Senior Member
Senior Member


Joined: 08 December 2003
Location: United States
Status: Offline
Points: 285
Post Options Post Options   Thanks (0) Thanks(0)   Quote Boyd Quote  Post ReplyReply Direct Link To This Post Topic: LicenseException in C#.Net
    Posted: 27 October 2004 at 2:03pm

I have been working extensively on building a C# application that incorporates some of the Codejock ActiveX controls.  Everything works fine when I run the application on my development machine.  When I deploy the application to another machine, I get the following exception:

System.ComponentModel.LicenseException: You do not have a license to use this ActiveX control.
  at System.Windows.Forms.AxHost.CreateInstance()
  at System.Windows.Forms.AxHost.GetOcxCreate()
  at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
  at System.Windows.Forms.AxHost.CreateHandle()
  at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
  at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
  at System.Windows.Forms.AsHost.EndInit()
  at MyApp.MainForm.InitializeComponent()
  at MyApp.MainForm..ctor()
  at MyApp.MainForm.Main()

This exeception is throw when the following line of my InitializeComponents method is executed (btw, this is all the code automatically generated by VS.Net editor from Designer where 'axCommandBars' is the name of my instance of CommandBars)

((System.ComponentModel.ISupportInitialize)(this.axCommandBa rs)).EndInit();

My guess is that it's looking for a run-time license to the control that only existed on the development machine.  With that in mind, I tried to use the 'CommandBars.GlobalSettings.License' property to set the text of my .LIC file.  The problem is that I can't seem to get this property set without throwing an exception.  Every time I try to set this property before the line that throws the LicenseException, I get an InvalidActiveXStateException.

Here's a snippet of the code I'm trying to use from the InitializeComponent() method:

System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeOf(MainForm));
this.axCommandBars = new AxXtremeCommandBars.AxCommandBars();
((System.ComponentModel.ISupportInitialize)(this.axCommandBa rs)).BeginInit();
this.SuspendLayout();
// Standard Property Assignments for CommandBars like 'Enabled', 'Locatation', etc
this.axCommandBars.GlobalSettings.License = "blah..blah..blah";
this.axCommandBars.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("ax CommandBars.OcxState")));
((System.ComponentModel.ISupportInitialize)(this.axCommandBa rs)).EndInit(); // This line throws 'InvalidLicense' exception

Any ideas?  I looked at the C# samples you provided, and I didn't find any example of specifying the license.  Thank you in advance!

Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 28 October 2004 at 7:26am
I haven't tried this in C# so I am just guessing, but in VB you need to make sure that you hard code the line breaks from the .lic file.  Maybe this will help, just use C# version of vbCrLf.

CommandBars.GlobalSettings.License = "Line1" & vbCrLf & "Line2" & vbCrLf & etc...
Back to Top
Boyd View Drop Down
Senior Member
Senior Member


Joined: 08 December 2003
Location: United States
Status: Offline
Points: 285
Post Options Post Options   Thanks (0) Thanks(0)   Quote Boyd Quote  Post ReplyReply Direct Link To This Post Posted: 28 October 2004 at 8:16am

I didn't include the full license in the following line, but I did include the line breaks in my application.

this.axCommandBars.GlobalSettings.License = "blah\r\nblah\r\nblah";

It appears that the problem I'm having is that you can't access the public members of CommandBars until after the control is fully initialized.  Trying to access them before full initialization throws an 'InvalidActiveXStateException' error.  However, when you finalize the control, it looks for the license.  It appears I'm stuck!  I can't set the license before initialization without throwing an error, and I can't initialize the control without a license.

Back to Top
Boyd View Drop Down
Senior Member
Senior Member


Joined: 08 December 2003
Location: United States
Status: Offline
Points: 285
Post Options Post Options   Thanks (0) Thanks(0)   Quote Boyd Quote  Post ReplyReply Direct Link To This Post Posted: 01 November 2004 at 8:59am

Here's the solution for C# usage that Oleg gave me through my IssueTrak request.  In the constructor for your main form, place the following code BEFORE the call to the 'InitializeComponents' method.

// Create Instance of Global Settings Class for CommandBars
XtremeCommandBars.CommandBarsGlobalSettingsClass settings = new XtremeCommandBars.CommandBarsGlobalSettingsClass();
// Now enter the first three lines of your license file
// (Note carriage return line feed '\r\n' at the end of each line)
settings.License = "CommandBars Control Copyright (c) 2003-2004 Codejock Software\r\n" +
  "PRODUCT-ID: XCB-ESD-ACTX-9500\r\n" +
  "VALIDATE-CODE: XXX-XXX-XXX-XXX";

This same technique must also be used for any other Codejock ActiveX controls.  It also appears that this step is only necessary on the main form of the application.  I have other classes stored in DLL's that also use the Codejock controls, and I was not required to set the licenses individually for each one.  I guess they truly are Global Settings

Thanks for the solution, Oleg!

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.125 seconds.