LicenseProvider.GetLicense() UsageMode

M

Mark Olbert

I'm confused about the UsageMode parameter passed to GetLicense() in my custom LicenseProvider.

When I create an instance of a licensed component in a custom UITypeEditor -- which pretty clearly means I'm in design mode! --
UsageMode gets passed as UsageMode.Runtime. This is bollixing up my license provider something fierce.

The licensed component is created by calling Invoke() on a ConstructorInfo object. I don't know why that should matter, but maybe it
does.

What do I need to do to ensure UsageMode gets set correctly?

- Mark
 
M

Mark Olbert

Okay, one workaround is to call IDesignerHost.CreateComponent(), rather than do an Invoke() on a ConstructorInfo. For some reason,
CreateComponent() sets the LicenseProvider.GetLicense() UsageMode to the correct value, i.e., Designtime, while the Invoke()
approach doesn't (BTW, I'd stil like to know why the Invoke() approach doesn't set UsageMode correctly).

However, one side-effect of CreateComponent() is that the created component gets added to the object I'm designing. I don't want
that. Basically, I create an instance of the component solely to query some of its properties, after which I want to throw it away.

I guess I can explicitly remove the component from the object's designer after I'm done with it, but that seems kludgy. Is there a
way to create a component at design time which doesn't get added to the object being designed?

- Mark
 
G

Gary Chang[MSFT]

Hi Mark,
When I create an instance of a licensed component in a custom UITypeEditor
-- which pretty clearly means I'm in design mode! --
UsageMode gets passed as UsageMode.Runtime.

I am afraid I am not very clear about the scenario you described. How do
you use your licensed component in the custom UITypeEditor?

Have you tried your licensed component in the standard winform designer,
which the LicenseUsageMode value at that sceanrio?


Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Olbert

Gary,

Let me see if I can clarify the context, if you'll pardon the pun.

TestSolution:
ProjectPackage (assembly name ProjectPackage)
references assembly DataPackage
defines component MyDataPackage, derived from SqlDataPackage (which is defined in assembly DataPackage)

ProjectForms (assembly name ProjectForms)
references ProjectPackage
references assembly DataForms
references assembly DataPackage
defines user control MyRecordControl, derived from RecordControl (which is defined in assembly DataForms)

SqlDataPackage is the licensed component.

When I debug the DataForms assembly (i.e., by running another instance of the IDE, for the solution TestSolution) I can step through
a custom UITypeEditor which is used to set a property for MyRecordControl. The property being set is the name of an item in a
collection defined in MyDataPackage. The custom UITypeEditor creates an instance of MyDataPackage in order to query one of its
collections for the allowable property values.

When I create that instance of MyDataPackage in the custom UITypeEditor like this:

IDesignerHost desHost = (IDesignerHost) provider.GetService(typeof(IDesignerHost));
Type pkgType = desHost.GetType("MyDataPackage");
ConstructorInfo ctor = pkgType.GetConstructor(Type.EmptyTypes);
SqlDataPackage thePkg = (SqlDataPackage) ctor.Invoke(null); // requires licensing

the GetLicense() method of the custom LicenseProvider gets called with a Runtime usage mode.

But if I create the instance of MyDataPackage in the custom UITypeEditor like this:

IDesignerHost desHost = (IDesignerHost) provider.GetService(typeof(IDesignerHost));
Type pkgType = desHost.GetType("MyDataPackage");
SqlDataPackage thePkg = (SqlDataPackage) desHost.CreateComponent(pkgType); // requires licensing

the GetLicense() method of the custom LicenseProvider gets called with a Designtime usage mode.

I don't understand why creating the instance via ConstructorInfo/Invoke() creates the license in a different context than
IDesignerHost.CreateComponent(). In both cases the construction is taking place at design-time, in code (i.e., the custom
UITypeEditor) that only has meaning in the design-time context.

Maybe the basic rule is "always use IDesignerHost to create stuff at design-time"?

- Mark
 
G

Gary Chang[MSFT]

Hi Mary,

Currently we are contacting our product team to review this issue, we will
update you as soon as we get anything out.

Thanks for your understanding.

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Gary Chang[MSFT]

Hi Mark,

I consulted this issue with our product team engineers, they suggest you
should create components via the IDesignerHost::CreateComponent method at
design time.

In addition to setting the license context to the DesignTime context, the
IDesignerHost::CreateComponent method will also:

1. create a site for the new component

2. site the new component

3. add the component to the IContainer.

Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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