System.Runtime.InteropServices.COMException Error

G

Guest

Hi,
I'm trying to make a COM call to an unmanaged COM object from C#. I've added
a reference to the COM object via 'Add References' within the IDE. It builds
and compiles fine with the following code and I can view the COM method in
the Object Browser so presumably it has registered the COM object correctly.

RunDC.CoRunDC DC;
DC = new RunDC.CoRunDCClass();

When I run however I get the following error message on the second line

"An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in <XXX>.exe

Additional information: Server execution failed"

Does anyone know what could be causing this error message. Any help much
appreciated
-Kim D
 
N

Nicholas Paldino [.NET/C# MVP]

Kim,

Are you running this in a thread that is not initialized for COM interop
(the ApartmentState property is set to ApartmentState.STA for STA COM
components), or is it running under a user that doesn't have rights for what
the COM object is doing during construction (is it trying to access a
resource like the registry, a database, or a file, and it's running in
ASP.NET perhaps)?

Does it work when you run from a windows forms app?

Do you have the component installed correctly on the machine you are
using it from? COM interop requires that the original component be
installed correctly, not just the wrapper.

These are just a few of the potential issues.
 
G

Guest

When I add a form to the COM project in the unmanaged project it works! I
didn't have any form associated with the COM object since all I wanted to do
was kick off another application. Thanks so much for your help
-Kim

Nicholas Paldino said:
Kim,

Are you running this in a thread that is not initialized for COM interop
(the ApartmentState property is set to ApartmentState.STA for STA COM
components), or is it running under a user that doesn't have rights for what
the COM object is doing during construction (is it trying to access a
resource like the registry, a database, or a file, and it's running in
ASP.NET perhaps)?

Does it work when you run from a windows forms app?

Do you have the component installed correctly on the machine you are
using it from? COM interop requires that the original component be
installed correctly, not just the wrapper.

These are just a few of the potential issues.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

kim d said:
Hi,
I'm trying to make a COM call to an unmanaged COM object from C#. I've
added
a reference to the COM object via 'Add References' within the IDE. It
builds
and compiles fine with the following code and I can view the COM method in
the Object Browser so presumably it has registered the COM object
correctly.

RunDC.CoRunDC DC;
DC = new RunDC.CoRunDCClass();

When I run however I get the following error message on the second line

"An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in <XXX>.exe

Additional information: Server execution failed"

Does anyone know what could be causing this error message. Any help much
appreciated
-Kim D
 
N

Nicholas Paldino [.NET/C# MVP]

Kim,

If this is the case, then it is because you do not have the thread
initialized for STA. Basically, you want to attach the STAThread attribute
to your Main method, or you want to use the following code:

// Set the current apartment state of the thread to STA.
Thread.CurrentThread.ApartmentState = ApartmentState.STA;


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

kim d said:
When I add a form to the COM project in the unmanaged project it works! I
didn't have any form associated with the COM object since all I wanted to
do
was kick off another application. Thanks so much for your help
-Kim

Nicholas Paldino said:
Kim,

Are you running this in a thread that is not initialized for COM
interop
(the ApartmentState property is set to ApartmentState.STA for STA COM
components), or is it running under a user that doesn't have rights for
what
the COM object is doing during construction (is it trying to access a
resource like the registry, a database, or a file, and it's running in
ASP.NET perhaps)?

Does it work when you run from a windows forms app?

Do you have the component installed correctly on the machine you are
using it from? COM interop requires that the original component be
installed correctly, not just the wrapper.

These are just a few of the potential issues.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

kim d said:
Hi,
I'm trying to make a COM call to an unmanaged COM object from C#. I've
added
a reference to the COM object via 'Add References' within the IDE. It
builds
and compiles fine with the following code and I can view the COM method
in
the Object Browser so presumably it has registered the COM object
correctly.

RunDC.CoRunDC DC;
DC = new RunDC.CoRunDCClass();

When I run however I get the following error message on the second line

"An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in <XXX>.exe

Additional information: Server execution failed"

Does anyone know what could be causing this error message. Any help
much
appreciated
-Kim D
 
G

Guest

I tried adding the code below and also perform a check to make sure the
calling thread is initialised for STA..However once I remove the form from my
unmanaged COM component and run it crashes with 'Server execution failed'
message. Perhaps there is something wrong with the type of COM component I'm
using.

Nicholas Paldino said:
Kim,

If this is the case, then it is because you do not have the thread
initialized for STA. Basically, you want to attach the STAThread attribute
to your Main method, or you want to use the following code:

// Set the current apartment state of the thread to STA.
Thread.CurrentThread.ApartmentState = ApartmentState.STA;


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

kim d said:
When I add a form to the COM project in the unmanaged project it works! I
didn't have any form associated with the COM object since all I wanted to
do
was kick off another application. Thanks so much for your help
-Kim

Nicholas Paldino said:
Kim,

Are you running this in a thread that is not initialized for COM
interop
(the ApartmentState property is set to ApartmentState.STA for STA COM
components), or is it running under a user that doesn't have rights for
what
the COM object is doing during construction (is it trying to access a
resource like the registry, a database, or a file, and it's running in
ASP.NET perhaps)?

Does it work when you run from a windows forms app?

Do you have the component installed correctly on the machine you are
using it from? COM interop requires that the original component be
installed correctly, not just the wrapper.

These are just a few of the potential issues.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,
I'm trying to make a COM call to an unmanaged COM object from C#. I've
added
a reference to the COM object via 'Add References' within the IDE. It
builds
and compiles fine with the following code and I can view the COM method
in
the Object Browser so presumably it has registered the COM object
correctly.

RunDC.CoRunDC DC;
DC = new RunDC.CoRunDCClass();

When I run however I get the following error message on the second line

"An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in <XXX>.exe

Additional information: Server execution failed"

Does anyone know what could be causing this error message. Any help
much
appreciated
-Kim D
 
W

Willy Denoyette [MVP]

No sure what you mean with - " a form to a COM project in the unmanaged
project". What exactly do you meen by this?
What kind of project is this unmanaged project, VB6, C++ or ?
What kind of COM object is it, library (dll) or server (exe)?
What kind of project is your managed project (winforms, console or ..)?

Willy.

Thread.CurrentThread.ApartmentState = ApartmentState.STA;


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

kim d said:
When I add a form to the COM project in the unmanaged project it works!
I
didn't have any form associated with the COM object since all I wanted
to
do
was kick off another application. Thanks so much for your help
-Kim

:

Kim,

Are you running this in a thread that is not initialized for COM
interop
(the ApartmentState property is set to ApartmentState.STA for STA COM
components), or is it running under a user that doesn't have rights
for
what
the COM object is doing during construction (is it trying to access a
resource like the registry, a database, or a file, and it's running in
ASP.NET perhaps)?

Does it work when you run from a windows forms app?

Do you have the component installed correctly on the machine you
are
using it from? COM interop requires that the original component be
installed correctly, not just the wrapper.

These are just a few of the potential issues.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,
I'm trying to make a COM call to an unmanaged COM object from C#.
I've
added
a reference to the COM object via 'Add References' within the IDE.
It
builds
and compiles fine with the following code and I can view the COM
method
in
the Object Browser so presumably it has registered the COM object
correctly.

RunDC.CoRunDC DC;
DC = new RunDC.CoRunDCClass();

When I run however I get the following error message on the second
line

"An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in <XXX>.exe

Additional information: Server execution failed"

Does anyone know what could be causing this error message. Any help
much
appreciated
-Kim D
 
G

Guest

I have a Delphi project containing an Automation object. When compiled an exe
is generated. My C# project is a Windows Application although I don't
currently have any forms associated with it. Really I'm using this C#
assembly to fire off a call to launch an unmanaged application.
 

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