Hi,
Thanks for the great feedback.

well, the issue is licensing.

I was using some static methods to set licenses like:

MyComponent.LoadLicenseKey( string key );
or
MyComponent.LoadLicenseFile( string path );

to globally load the license file.

Then, if they didn't load the license (before component initialization)I
could throw an exception when they call

MyComponent mc = new MyComponent();



and becasue I have multiple ctors (with parameters), internally, I would
always call

MyComponent( [some parameters here] ) :this()
{
    //code here
}

where the 'default' ctor looks like:

MyComponent()
{
    //do license check
    if( licenseFailed )
        throw new LicenseException( "you can initizlie the license by
calling MyComponent.LoadLicense()" ); //or any other helpful information

    //initialize some stuff
}


I didn't want to do a license check from all the methods (or a subset of
them), so I was keeping it nice and simple in the default ctor, but then
this issue arises when people want to use the components from com.

Any thoughts?

Cheers!
Dave
----- Original Message -----
From: "J. Merrill" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, June 09, 2004 1:46 PM
Subject: Re: [ADVANCED-DOTNET] checking for COM


> The COM environments cannot call a constructor with parameters, so you can
know it's a .NET routine calling if they call a constructor that takes
parameters.  (But of course a .NET program could call your not-parameterized
constructor, unless you document that if they do so they will get whatever
reduced or modified functionality that's inflicted on COM clients.)
>
> You probably should add a (private) boolean field to keep track of this,
as there's no easy (cheap) way to know if the method that wants to know
isn't a constructor.
>
> Also, AFAIK, a COM call can't call your class's static methods.
>
> I too am curious about why you want this.  If it's really really
important, you might possibly be able to figure it out (in the
non-parameterized constructor) using a stack-walk (but then I think your
callers will need Reflection privileges when that would possibly not be the
case otherwise).
>
> Good luck...
>
> At 07:32 AM 6/9/2004, dave wanta wrote
> >hi all,
> >>From a .NET component (class library), is it possible to check if the
ctor
> >is being called from a .NET environment, or a COM environment? (like VB
or
> >classic ASP) ?
> >
> >Thanks,
> >Dave
>
>
> J. Merrill / Analytical Software Corp
>
> ===================================
> This list is hosted by DevelopMentorŪ  http://www.develop.com
> Some .NET courses you may be interested in:
>
> NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
> http://www.develop.com/courses/gaspdotnetls
>
> View archives and manage your subscription(s) at
http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to