C# and COM+ Constuct

G

Guest

All,

I am trying to use the COM+ constructor string as follows:

[ConstructionEnabled (true)]
public sealed class xxxx: ServicedComponent
{

public override void Construct(string constructString)
{

}
{

But when I build the project I get the following error:

C:\xxx.cs(33): xxxxxx.Construct(string)': cannot change access modifiers
when overriding 'protected' inherited member
'System.EnterpriseServices.ServicedComponent.Construct(string)'

What am I doing wrong?

Thanks
Msuk
 
O

Ollie Riches

The 'Construct' method is defined as 'protected' in the ServicedComponent
class you can't change the access modifier in your derived class - this is
what the compiler error says...

You can't call this method externally from the class....

HTH

Ollie Riches
 
G

Guest

Hi,

All the examples show that you can have it as a public method e.g

http://www.ondotnet.com/pub/a/dotnet/excerpt/com_dotnet_ch10/?page=6

What should it be?

Thanks
Msuk

Ollie Riches said:
The 'Construct' method is defined as 'protected' in the ServicedComponent
class you can't change the access modifier in your derived class - this is
what the compiler error says...

You can't call this method externally from the class....

HTH

Ollie Riches

msuk said:
All,

I am trying to use the COM+ constructor string as follows:

[ConstructionEnabled (true)]
public sealed class xxxx: ServicedComponent
{

public override void Construct(string constructString)
{

}
{

But when I build the project I get the following error:

C:\xxx.cs(33): xxxxxx.Construct(string)': cannot change access modifiers
when overriding 'protected' inherited member
'System.EnterpriseServices.ServicedComponent.Construct(string)'

What am I doing wrong?

Thanks
Msuk
 
R

Richard Blewett [DevelopMentor]

IIRC IObjectConstruct (the COM+ construction interface) has the signature

IObjectConstruct
{
HRESULT Construct(IDispatch* pCtorObj);
}

This is obviously not the same signature as the overridable Construct method from ServiceComponent. So ServicedComponent implements the interface and then it's implementation of IObjectConstruct::Construct calls a protected virtual Construct method which you can override. Thats why the Construct method you override is protected rather than public

Regards]

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

The 'Construct' method is defined as 'protected' in the ServicedComponent
class you can't change the access modifier in your derived class - this is
what the compiler error says...

You can't call this method externally from the class....

HTH

Ollie Riches
 
W

Willy Denoyette [MVP]

You can't change the access modifier (he, but that's what the compiler
say's..;-).

Change your method definition to:

protected override void Construct(string s) {
..

}

And don't forget that passing a string is done through the
ConstructionEnabledAttribute.

[ConstructionEnabled(Enabled=true, Default="Test string")]


Willy.
 

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