Problems with licensing a control

N

~~~ .NET Ed ~~~

I have a problem trying out the "simple" component/control licensing scheme
in
VS.NET 2003 (I use C#). I have read several articles, most of them with
differing
information, read the MS documentation on MSDN and with VS.NET but can't get
the bloody thing working. Here are the steps I followed in hope somebody can
bring some light into the subject:

1. Information about my "licensed" component:

Namespace: Test.Common.Controls
Project name: CtMyControl
Class Name: MyControl
Assembly Name: Test.CtMyControl.dll
Directory: E:\Develop\Common\CtMyControl\obj\Release\
Build Type: Release


2. I added the Licensed attribute to my licensed control specifying for
now the simple provider which I would expect works out of the box.
Also added the private license member, its validation in the constructor
and the disposing of the license.

namespace Test.Common.Controls
{
[LicenseProvider(typeof(LicFileLicenseProvider))]
public sealed class MyControl
{
private License validatedLicense = null;

public MyControl()
{
InitializeComponent();
this.validatedLicense = LicenseManager.Validate(typeof(MyControl),
this);
} // Constructor

protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}

// Liberate the license, don't let it linger in memory
if (this.validatedLicense != null)
{
this.validatedLicense.Dispose();
this.validatedLicense = null;
}
}
base.Dispose( disposing );
} // Dispose
} // MyControl
} // namespace


So far this part works because when I try to add the licensed component to a
form
I get an exception in design mode. (more on that later).

3. The test application where I am trying to put the control is a Release
type
of build as well.
It has a reference to the DLL that contains the license control, the
properties of this reference show:

Name: Test.CtMyControl
Copy Local: True
Identity: Test.CtMyControl
Path: E:\Develop\common\CtMyControl\obj\Release\Test.CtMyControl.dll

4. Following the instructions (which differ from article to article found on
the web, even MS docs seem to be slightly inconsistent) I placed a
License
file in the same directory that Path of the above named Reference is
located:

Directory: E:\Develop\Common\CtMyControl\obj\Release\
Filename: Test.Common.Controls.MyControl.lic

notice that the filename is the fully qualified name (namespace+class) of
the control to be licensed. The contents of this "license" file are:

Test.Common.Controls.MyControl is a licensed component.

exactly as shown above without leading or trailing spaces. Some articles
say
that the trailing dot is necessary, some simply omit the article. I tried
both things to no avail.

Also some articles seem to suggest that the ",Assembly" has to be
appended
but it is not clear if that is for the .LIC file or the .LICX file.


Ok, so far so good. Now I rebuilt the whole solution and proceeded to add
the
"licensed" component to a form and BOOM:

"An exception occurred while trying to create and instance
of Test.Common.Controls.MyControl. The exception was "an instance
of type 'Test.Common.Controls.MyControl' was being created, and a valid
license could not be granted for the type
'Test.Common.Controls.MyControl'
Please contact the manufacturer of the component for more information."

This is the exception pop up I would expect if there was no license for the
component. So what am I missing here? I am
- Using the simple LicFileLicenseProvider provided by .NET as start point
- Added the attribute to the class that implements the control
- Added the license container in the control class
- Validated the license in the constructor (obviosly here the
exception is thrown for a reason I don't know)
- Disposed of the license in the Dispose method
- Created a .LIC file with the full name of the class and placed it
in the same directory shown in the assembly reference of the project
where I am attempting to use the component.

So, what else??? any help would be greatly appreciated.

Thx,
E.
 
N

~~~ .NET Ed ~~~

Given the overwhelming response ;) I decided to dump the "works out of the
box" LicFileLicenseProvider. I
found an excellent article with a sample implementation of a license
provider that works similarly to the
LicFileLicenseProvider. Works perfectly and there you can actually see what
is happening and where it is
looking for what.

Anyway... I have found a new problem but this time with the actual
LicenseProvider API. IMHO it is a
defect and so here is what I have noticed while debugging the working code.
I show it in steps so that there
are no misinterpretations and is easy to chew.

1. A form with the licensed control is instantiated (test application).
2. The licensed control invokes LicenseManager.Validate.
3. The associated custom License Provider (works like the
LicLicenseProvider) is called by the LicenseManager
by using the GetLicense() method which is overriden in the custom class
as part of the implementation. AT
this point we are in the MyLicenseProvider.GetLicense() method frame.
This method receives a context, type and
instance objects as parameters.
4. The context passed to GetLicense() is NOT null. It shows it is in Runtime
Usage Mode. OK so far.
5. Now things get strange here while attempting to obtain the license saved
in the key:
a) Code snippet for one type of attempt:
string savedKey = context.GetSavedKey(type, null);
This returns NULL, that is no saved key.
b) Code snippet for a slightly different attempt:
string savedKey = context.GetSavedKey(type, instance.GetType());
This returns NULL, ie. no saved key found.

Ok, at this point you would be inclined to think there is no saved key
because GetSavedKey says so... Well, NOT TRUE. When I examing the instance
of the context object using the QuickWatch window I see that the
non-public member System.ComponentMode.Design.RuntimeLicenseContext expanded
shows a sub-member
named savedLicensedKeys (remember you can't access this because GetSavedKey
is SUPPOSED to do it but it doesn't). This opaque savedLicenseKeys member of
context shows "Count = 1". Furthermore, expanding it shows that the only
"saved-yet-unreachable" key is actually the key I am looking for!!!

So my question is why, if GetSavedKeys is supposed to act as the way to
search and retrieve the keys, and it is
passed the correct parameters it is still unable to retrieved the saved
key???? call me crazy but this seems like
a bug to me.

Any ideas? I hope I am proven wrong because otherwise it sounds like waiting
a long time for a fix.

Regards,
E.

~~~ .NET Ed ~~~ said:
I have a problem trying out the "simple" component/control licensing scheme
in
VS.NET 2003 (I use C#). I have read several articles, most of them with
differing
information, read the MS documentation on MSDN and with VS.NET but can't get
the bloody thing working. Here are the steps I followed in hope somebody can
bring some light into the subject:

1. Information about my "licensed" component:

Namespace: Test.Common.Controls
Project name: CtMyControl
Class Name: MyControl
Assembly Name: Test.CtMyControl.dll
Directory: E:\Develop\Common\CtMyControl\obj\Release\
Build Type: Release


2. I added the Licensed attribute to my licensed control specifying for
now the simple provider which I would expect works out of the box.
Also added the private license member, its validation in the constructor
and the disposing of the license.

namespace Test.Common.Controls
{
[LicenseProvider(typeof(LicFileLicenseProvider))]
public sealed class MyControl
{
private License validatedLicense = null;

public MyControl()
{
InitializeComponent();
this.validatedLicense = LicenseManager.Validate(typeof(MyControl),
this);
} // Constructor

protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}

// Liberate the license, don't let it linger in memory
if (this.validatedLicense != null)
{
this.validatedLicense.Dispose();
this.validatedLicense = null;
}
}
base.Dispose( disposing );
} // Dispose
} // MyControl
} // namespace


So far this part works because when I try to add the licensed component to a
form
I get an exception in design mode. (more on that later).

3. The test application where I am trying to put the control is a Release
type
of build as well.
It has a reference to the DLL that contains the license control, the
properties of this reference show:

Name: Test.CtMyControl
Copy Local: True
Identity: Test.CtMyControl
Path: E:\Develop\common\CtMyControl\obj\Release\Test.CtMyControl.dll

4. Following the instructions (which differ from article to article found on
the web, even MS docs seem to be slightly inconsistent) I placed a
License
file in the same directory that Path of the above named Reference is
located:

Directory: E:\Develop\Common\CtMyControl\obj\Release\
Filename: Test.Common.Controls.MyControl.lic

notice that the filename is the fully qualified name (namespace+class) of
the control to be licensed. The contents of this "license" file are:

Test.Common.Controls.MyControl is a licensed component.

exactly as shown above without leading or trailing spaces. Some articles
say
that the trailing dot is necessary, some simply omit the article. I tried
both things to no avail.

Also some articles seem to suggest that the ",Assembly" has to be
appended
but it is not clear if that is for the .LIC file or the .LICX file.


Ok, so far so good. Now I rebuilt the whole solution and proceeded to add
the
"licensed" component to a form and BOOM:

"An exception occurred while trying to create and instance
of Test.Common.Controls.MyControl. The exception was "an instance
of type 'Test.Common.Controls.MyControl' was being created, and a valid
license could not be granted for the type
'Test.Common.Controls.MyControl'
Please contact the manufacturer of the component for more information."

This is the exception pop up I would expect if there was no license for the
component. So what am I missing here? I am
- Using the simple LicFileLicenseProvider provided by .NET as start point
- Added the attribute to the class that implements the control
- Added the license container in the control class
- Validated the license in the constructor (obviosly here the
exception is thrown for a reason I don't know)
- Disposed of the license in the Dispose method
- Created a .LIC file with the full name of the class and placed it
in the same directory shown in the assembly reference of the project
where I am attempting to use the component.

So, what else??? any help would be greatly appreciated.

Thx,
E.
 
R

roland

I have spent some time with the licensing issue.
I restricted my design to a design time file license using crypto.
If you want to check a license in both usage modes, you need a license at
design time, and the key is saved by calling SetSavedLicensekey in a
resource file and compiled in the calling (or containing) assembly and you
have to recur to GetSavedLicenseKey in Runtime mode to "build" your license
without the design time license file. The Microsoft documentation states
that both methods above only work when overridden (there is a sample
available).This may explain why the data is there but only private to the
member. Since I didn't like that the license key is stored as a resource in
the calling assembly, I didn't go for this approach. Moreover, I saw some
messages where people complained about the fact that installing an updated
assembly invalidated the runtime license.
Roland

~~~ .NET Ed ~~~ said:
Given the overwhelming response ;) I decided to dump the "works out of the
box" LicFileLicenseProvider. I
found an excellent article with a sample implementation of a license
provider that works similarly to the
LicFileLicenseProvider. Works perfectly and there you can actually see what
is happening and where it is
looking for what.

Anyway... I have found a new problem but this time with the actual
LicenseProvider API. IMHO it is a
defect and so here is what I have noticed while debugging the working code.
I show it in steps so that there
are no misinterpretations and is easy to chew.

1. A form with the licensed control is instantiated (test application).
2. The licensed control invokes LicenseManager.Validate.
3. The associated custom License Provider (works like the
LicLicenseProvider) is called by the LicenseManager
by using the GetLicense() method which is overriden in the custom class
as part of the implementation. AT
this point we are in the MyLicenseProvider.GetLicense() method frame.
This method receives a context, type and
instance objects as parameters.
4. The context passed to GetLicense() is NOT null. It shows it is in Runtime
Usage Mode. OK so far.
5. Now things get strange here while attempting to obtain the license saved
in the key:
a) Code snippet for one type of attempt:
string savedKey = context.GetSavedKey(type, null);
This returns NULL, that is no saved key.
b) Code snippet for a slightly different attempt:
string savedKey = context.GetSavedKey(type, instance.GetType());
This returns NULL, ie. no saved key found.

Ok, at this point you would be inclined to think there is no saved key
because GetSavedKey says so... Well, NOT TRUE. When I examing the instance
of the context object using the QuickWatch window I see that the
non-public member System.ComponentMode.Design.RuntimeLicenseContext expanded
shows a sub-member
named savedLicensedKeys (remember you can't access this because GetSavedKey
is SUPPOSED to do it but it doesn't). This opaque savedLicenseKeys member of
context shows "Count = 1". Furthermore, expanding it shows that the only
"saved-yet-unreachable" key is actually the key I am looking for!!!

So my question is why, if GetSavedKeys is supposed to act as the way to
search and retrieve the keys, and it is
passed the correct parameters it is still unable to retrieved the saved
key???? call me crazy but this seems like
a bug to me.

Any ideas? I hope I am proven wrong because otherwise it sounds like waiting
a long time for a fix.

Regards,
E.

~~~ .NET Ed ~~~ said:
I have a problem trying out the "simple" component/control licensing scheme
in
VS.NET 2003 (I use C#). I have read several articles, most of them with
differing
information, read the MS documentation on MSDN and with VS.NET but can't get
the bloody thing working. Here are the steps I followed in hope somebody can
bring some light into the subject:

1. Information about my "licensed" component:

Namespace: Test.Common.Controls
Project name: CtMyControl
Class Name: MyControl
Assembly Name: Test.CtMyControl.dll
Directory: E:\Develop\Common\CtMyControl\obj\Release\
Build Type: Release


2. I added the Licensed attribute to my licensed control specifying for
now the simple provider which I would expect works out of the box.
Also added the private license member, its validation in the constructor
and the disposing of the license.

namespace Test.Common.Controls
{
[LicenseProvider(typeof(LicFileLicenseProvider))]
public sealed class MyControl
{
private License validatedLicense = null;

public MyControl()
{
InitializeComponent();
this.validatedLicense = LicenseManager.Validate(typeof(MyControl),
this);
} // Constructor

protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}

// Liberate the license, don't let it linger in memory
if (this.validatedLicense != null)
{
this.validatedLicense.Dispose();
this.validatedLicense = null;
}
}
base.Dispose( disposing );
} // Dispose
} // MyControl
} // namespace


So far this part works because when I try to add the licensed component
to
a
form
I get an exception in design mode. (more on that later).

3. The test application where I am trying to put the control is a Release
type
of build as well.
It has a reference to the DLL that contains the license control, the
properties of this reference show:

Name: Test.CtMyControl
Copy Local: True
Identity: Test.CtMyControl
Path: E:\Develop\common\CtMyControl\obj\Release\Test.CtMyControl.dll

4. Following the instructions (which differ from article to article
found
on
the web, even MS docs seem to be slightly inconsistent) I placed a
License
file in the same directory that Path of the above named Reference is
located:

Directory: E:\Develop\Common\CtMyControl\obj\Release\
Filename: Test.Common.Controls.MyControl.lic

notice that the filename is the fully qualified name
(namespace+class)
of
the control to be licensed. The contents of this "license" file are:

Test.Common.Controls.MyControl is a licensed component.

exactly as shown above without leading or trailing spaces. Some articles
say
that the trailing dot is necessary, some simply omit the article. I tried
both things to no avail.

Also some articles seem to suggest that the ",Assembly" has to be
appended
but it is not clear if that is for the .LIC file or the .LICX file.


Ok, so far so good. Now I rebuilt the whole solution and proceeded to add
the
"licensed" component to a form and BOOM:

"An exception occurred while trying to create and instance
of Test.Common.Controls.MyControl. The exception was "an instance
of type 'Test.Common.Controls.MyControl' was being created, and a valid
license could not be granted for the type
'Test.Common.Controls.MyControl'
Please contact the manufacturer of the component for more information."

This is the exception pop up I would expect if there was no license for the
component. So what am I missing here? I am
- Using the simple LicFileLicenseProvider provided by .NET as start point
- Added the attribute to the class that implements the control
- Added the license container in the control class
- Validated the license in the constructor (obviosly here the
exception is thrown for a reason I don't know)
- Disposed of the license in the Dispose method
- Created a .LIC file with the full name of the class and placed it
in the same directory shown in the assembly reference of the project
where I am attempting to use the component.

So, what else??? any help would be greatly appreciated.

Thx,
E.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top