wrong license text compiled to executable

G

Guest

It seems to me, that the wrong license text is compiled to the executable
when using a custom license provider derived from LicFileLicenseProvider.

I'm trying to protect a control by a license text file. So I created one
project for the usercontrol and another for testing the licensed control (see
code below). After inserting the LicenseProviderAttribute using the
LicFileLicenseProvider with the required text in the lic file, I put the lic
file in the bin\Debug and in the obj\Debug to avoid problems caused by the
tester application consuming a licensed control from the same solution (Q
814342).
Everything worked fine: lic file must be present to use control in tester
application, license is compiled to the tester application, tester runs
without any lic file.

My next step was to build a custom license provider by deriving from
LicFileLicenseProvider. To keep it simple, the new version of IsKeyValid(…)
checks the key for a static string value. I inserted the new provider in the
attribute and changed the text in both lic files. The result is this:
Using the control in the tester at design time still works. Even deleting
the control and inserting a new instance works (even so the licenses.licx has
some additional entries for already deleted controls, that make no sense to
me!). but running the compiled tester application fails, because of missing
license for the control.
Searching for the cause I found out, that the license text compiled to the
tester is simple wrong! I can see that obj\Debug\Tester.exe.licenses contains
a license text for the control that is compatible with the license text
expected from LicFileLicenseProvider ('FullName is a licensed component.')
but not the text provided in the lic file(s).
This problem also occurrs when the custom provider and a licensed control is
created in a new project from the scratch. So the wrong license text in the
first case is not just a left over from first using the original
LicFileLicenseProvider.

If you have any idea, please let me know. Thanks in advance

pp


CODE:

using System;
using System.ComponentModel;

namespace LicControl1
{

public class MyLicFileLicenseProvider : LicFileLicenseProvider
{
public MyLicFileLicenseProvider()
{}

protected override bool IsKeyValid(string key, Type type)
{
return (key=="whatever");
}

}
}

############################

using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace LicControl1
{
[LicenseProviderAttribute(typeof(MyLicFileLicenseProvider))]
public class UserControlLic0 : System.Windows.Forms.UserControl
{

#region ctor

private System.ComponentModel.Container components = null;

public UserControlLic0()
{
license = LicenseManager.Validate(typeof(UserControlLic0), this);
InitializeComponent();
}

~UserControlLic0()
{
if(!IsDisposed)
Dispose();
}

#endregion

#region license

private License license = null;

#endregion


#region dispose

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

#endregion

#region designer

private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}

#endregion

}
}
 
G

Guest

I had the same problem. Your comments were very helpful, as it enlighted me
to look into the generated .licenses file in the Obj folder and see that the
license key string was not correct - it was the original .lic file contents.

I solved the problem by overriding the GetKey() method, and actually reading
the .lic file myself, from the folder of the type's assembly file, this way:

protected override string GetKey(Type type)
{
try
{
using (StreamReader r = new
StreamReader(string.Format("{0}/{1}.lic",
Path.GetDirectoryName(type.Assembly.Location), type.FullName)))
{
return r.ReadLine();
}
}
catch (IOException) { return base.GetKey(type); }
}

Hope it helps you and/or other people - as the issue was very frustrating to
me until I solved it.

--
Sorin Dolha, DlhSoft

pachyphloia said:
It seems to me, that the wrong license text is compiled to the executable
when using a custom license provider derived from LicFileLicenseProvider.

I'm trying to protect a control by a license text file. So I created one
project for the usercontrol and another for testing the licensed control (see
code below). After inserting the LicenseProviderAttribute using the
LicFileLicenseProvider with the required text in the lic file, I put the lic
file in the bin\Debug and in the obj\Debug to avoid problems caused by the
tester application consuming a licensed control from the same solution (Q
814342).
Everything worked fine: lic file must be present to use control in tester
application, license is compiled to the tester application, tester runs
without any lic file.

My next step was to build a custom license provider by deriving from
LicFileLicenseProvider. To keep it simple, the new version of IsKeyValid(…)
checks the key for a static string value. I inserted the new provider in the
attribute and changed the text in both lic files. The result is this:
Using the control in the tester at design time still works. Even deleting
the control and inserting a new instance works (even so the licenses.licx has
some additional entries for already deleted controls, that make no sense to
me!). but running the compiled tester application fails, because of missing
license for the control.
Searching for the cause I found out, that the license text compiled to the
tester is simple wrong! I can see that obj\Debug\Tester.exe.licenses contains
a license text for the control that is compatible with the license text
expected from LicFileLicenseProvider ('FullName is a licensed component.')
but not the text provided in the lic file(s).
This problem also occurrs when the custom provider and a licensed control is
created in a new project from the scratch. So the wrong license text in the
first case is not just a left over from first using the original
LicFileLicenseProvider.

If you have any idea, please let me know. Thanks in advance

pp


CODE:

using System;
using System.ComponentModel;

namespace LicControl1
{

public class MyLicFileLicenseProvider : LicFileLicenseProvider
{
public MyLicFileLicenseProvider()
{}

protected override bool IsKeyValid(string key, Type type)
{
return (key=="whatever");
}

}
}

############################

using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace LicControl1
{
[LicenseProviderAttribute(typeof(MyLicFileLicenseProvider))]
public class UserControlLic0 : System.Windows.Forms.UserControl
{

#region ctor

private System.ComponentModel.Container components = null;

public UserControlLic0()
{
license = LicenseManager.Validate(typeof(UserControlLic0), this);
InitializeComponent();
}

~UserControlLic0()
{
if(!IsDisposed)
Dispose();
}

#endregion

#region license

private License license = null;

#endregion


#region dispose

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

#endregion

#region designer

private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}

#endregion

}
}
 

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

Top