473,398 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Create COM component via late binding

I am trying to instantiate a COM component in C# via late binding. The
component appears to be launched, then it automatically gets unloaded. That
is, the instance is unloaded after the CreateInstance returns.

Any idea of what could be the problem? Thanks a lot.

Here is the code segment I am using:

Object target;

Type oType = Type.GetTypeFromProgID("my.application", true);
if (oType != null)

{

target = Activator.CreateInstance(oType);

if (target != null)

{

success = true;

}

}
Aug 4 '06 #1
7 2007
jwang,

Either CreateInstance should throw, or return a value. What is the
exception that is being thrown? I doubt it is NullReferenceException.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"jwang" <jw***@newsgroups.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>I am trying to instantiate a COM component in C# via late binding. The
component appears to be launched, then it automatically gets unloaded.
That is, the instance is unloaded after the CreateInstance returns.

Any idea of what could be the problem? Thanks a lot.

Here is the code segment I am using:

Object target;

Type oType = Type.GetTypeFromProgID("my.application", true);
if (oType != null)

{

target = Activator.CreateInstance(oType);

if (target != null)

{

success = true;

}

}


Aug 4 '06 #2
Nicholas,
Thanks for responding to my question.

CreateInstance does not throw an exception, and it returns a
System._ComObject. The COM component I try to invoke is a out-of-process
component. From the Task Manager, I can see it was created and then went
away. (I used the same method on Excel.Application, it works fine.)

Also, I try with ComImport to explicitly import the type, and then use new
to instantiate the component, but get the same problem.

jwang
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:OO**************@TK2MSFTNGP05.phx.gbl...
jwang,

Either CreateInstance should throw, or return a value. What is the
exception that is being thrown? I doubt it is NullReferenceException.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"jwang" <jw***@newsgroups.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>>I am trying to instantiate a COM component in C# via late binding. The
component appears to be launched, then it automatically gets unloaded.
That is, the instance is unloaded after the CreateInstance returns.

Any idea of what could be the problem? Thanks a lot.

Here is the code segment I am using:

Object target;

Type oType = Type.GetTypeFromProgID("my.application", true);
if (oType != null)

{

target = Activator.CreateInstance(oType);

if (target != null)

{

success = true;

}

}



Aug 4 '06 #3
jwang,

This does not indicate an issue with .NET, but rather, the COM server
(which is out of process) is being shut down.

If you try and create the object through say, vb script, do you get the
same result?

Also, what do you have the ApartmentState set to on your thread?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"jwang" <jw***@newsgroups.nospamwrote in message
news:On****************@TK2MSFTNGP03.phx.gbl...
Nicholas,
Thanks for responding to my question.

CreateInstance does not throw an exception, and it returns a
System._ComObject. The COM component I try to invoke is a out-of-process
component. From the Task Manager, I can see it was created and then went
away. (I used the same method on Excel.Application, it works fine.)

Also, I try with ComImport to explicitly import the type, and then use new
to instantiate the component, but get the same problem.

jwang
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:OO**************@TK2MSFTNGP05.phx.gbl...
>jwang,

Either CreateInstance should throw, or return a value. What is the
exception that is being thrown? I doubt it is NullReferenceException.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"jwang" <jw***@newsgroups.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>>>I am trying to instantiate a COM component in C# via late binding. The
component appears to be launched, then it automatically gets unloaded.
That is, the instance is unloaded after the CreateInstance returns.

Any idea of what could be the problem? Thanks a lot.

Here is the code segment I am using:

Object target;

Type oType = Type.GetTypeFromProgID("my.application", true);
if (oType != null)

{

target = Activator.CreateInstance(oType);

if (target != null)

{

success = true;

}

}




Aug 4 '06 #4
Is it possible that the managed object is being garbage collected and
releasing references? Then the COM server just goes away.
--
Phil Wilson
[Microsoft MVP-Windows Installer]
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:O0**************@TK2MSFTNGP06.phx.gbl...
jwang,

This does not indicate an issue with .NET, but rather, the COM server
(which is out of process) is being shut down.

If you try and create the object through say, vb script, do you get the
same result?

Also, what do you have the ApartmentState set to on your thread?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"jwang" <jw***@newsgroups.nospamwrote in message
news:On****************@TK2MSFTNGP03.phx.gbl...
>Nicholas,
Thanks for responding to my question.

CreateInstance does not throw an exception, and it returns a
System._ComObject. The COM component I try to invoke is a out-of-process
component. From the Task Manager, I can see it was created and then went
away. (I used the same method on Excel.Application, it works fine.)

Also, I try with ComImport to explicitly import the type, and then use
new to instantiate the component, but get the same problem.

jwang
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:OO**************@TK2MSFTNGP05.phx.gbl...
>>jwang,

Either CreateInstance should throw, or return a value. What is the
exception that is being thrown? I doubt it is NullReferenceException.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"jwang" <jw***@newsgroups.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl.. .
I am trying to instantiate a COM component in C# via late binding. The
component appears to be launched, then it automatically gets unloaded.
That is, the instance is unloaded after the CreateInstance returns.

Any idea of what could be the problem? Thanks a lot.

Here is the code segment I am using:

Object target;

Type oType = Type.GetTypeFromProgID("my.application", true);
if (oType != null)

{

target = Activator.CreateInstance(oType);

if (target != null)

{

success = true;

}

}




Aug 4 '06 #5
I have been calling the application in VB6 suing CreateObject(). It always
works as expected.

I do not explicitly set the thread. Is that something I should do? I just
attempt to write a C# class that invokes that COM server.

It seems that the reference to the COM server is lost when CreateInstnace
returns. Just do not know what has caused that.

Thanks.
jwang

"Phil Wilson" <pd*******@nospam.cox.netwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Is it possible that the managed object is being garbage collected and
releasing references? Then the COM server just goes away.
--
Phil Wilson
[Microsoft MVP-Windows Installer]
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:O0**************@TK2MSFTNGP06.phx.gbl...
>jwang,

This does not indicate an issue with .NET, but rather, the COM server
(which is out of process) is being shut down.

If you try and create the object through say, vb script, do you get
the same result?

Also, what do you have the ApartmentState set to on your thread?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"jwang" <jw***@newsgroups.nospamwrote in message
news:On****************@TK2MSFTNGP03.phx.gbl...
>>Nicholas,
Thanks for responding to my question.

CreateInstance does not throw an exception, and it returns a
System._ComObject. The COM component I try to invoke is a
out-of-process component. From the Task Manager, I can see it was
created and then went away. (I used the same method on
Excel.Application, it works fine.)

Also, I try with ComImport to explicitly import the type, and then use
new to instantiate the component, but get the same problem.

jwang
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:OO**************@TK2MSFTNGP05.phx.gbl...
jwang,

Either CreateInstance should throw, or return a value. What is the
exception that is being thrown? I doubt it is NullReferenceException.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"jwang" <jw***@newsgroups.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl. ..
>I am trying to instantiate a COM component in C# via late binding. The
>component appears to be launched, then it automatically gets unloaded.
>That is, the instance is unloaded after the CreateInstance returns.
>
Any idea of what could be the problem? Thanks a lot.
>
Here is the code segment I am using:
>
Object target;
>
Type oType = Type.GetTypeFromProgID("my.application", true);
if (oType != null)
>
{
>
target = Activator.CreateInstance(oType);
>
if (target != null)
>
{
>
success = true;
>
}
>
}
>
>




Aug 4 '06 #6
What kind of client are you talking about? Please post a simple client that
illustrates the issue.
If the COM out-proc server ends it's because it stops running for a reason
known by the server not because of the client.
What happens if you create an instance of say Excel or Word from the same
client?

Willy.


"jwang" <jw***@newsgroups.nospamwrote in message
news:OX****************@TK2MSFTNGP06.phx.gbl...
|I have been calling the application in VB6 suing CreateObject(). It always
| works as expected.
|
| I do not explicitly set the thread. Is that something I should do? I
just
| attempt to write a C# class that invokes that COM server.
|
| It seems that the reference to the COM server is lost when CreateInstnace
| returns. Just do not know what has caused that.
|
| Thanks.
| jwang
|
|
|
|
|
| "Phil Wilson" <pd*******@nospam.cox.netwrote in message
| news:%2****************@TK2MSFTNGP06.phx.gbl...
| Is it possible that the managed object is being garbage collected and
| releasing references? Then the COM server just goes away.
| --
| Phil Wilson
| [Microsoft MVP-Windows Installer]
| "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
| in message news:O0**************@TK2MSFTNGP06.phx.gbl...
| >jwang,
| >>
| > This does not indicate an issue with .NET, but rather, the COM
server
| >(which is out of process) is being shut down.
| >>
| > If you try and create the object through say, vb script, do you get
| >the same result?
| >>
| > Also, what do you have the ApartmentState set to on your thread?
| >>
| >>
| >--
| > - Nicholas Paldino [.NET/C# MVP]
| > - mv*@spam.guard.caspershouse.com
| >>
| >"jwang" <jw***@newsgroups.nospamwrote in message
| >news:On****************@TK2MSFTNGP03.phx.gbl...
| >>Nicholas,
| >>Thanks for responding to my question.
| >>>
| >>CreateInstance does not throw an exception, and it returns a
| >>System._ComObject. The COM component I try to invoke is a
| >>out-of-process component. From the Task Manager, I can see it was
| >>created and then went away. (I used the same method on
| >>Excel.Application, it works fine.)
| >>>
| >>Also, I try with ComImport to explicitly import the type, and then use
| >>new to instantiate the component, but get the same problem.
| >>>
| >>jwang
| >>>
| >>>
| >>"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
wrote
| >>in message news:OO**************@TK2MSFTNGP05.phx.gbl...
| >>>jwang,
| >>>>
| >>> Either CreateInstance should throw, or return a value. What is
the
| >>>exception that is being thrown? I doubt it is
NullReferenceException.
| >>>>
| >>>>
| >>>--
| >>> - Nicholas Paldino [.NET/C# MVP]
| >>> - mv*@spam.guard.caspershouse.com
| >>>>
| >>>"jwang" <jw***@newsgroups.nospamwrote in message
| >>>news:%2****************@TK2MSFTNGP06.phx.gbl. ..
| >>>>>I am trying to instantiate a COM component in C# via late binding.
The
| >>>>>component appears to be launched, then it automatically gets
unloaded.
| >>>>>That is, the instance is unloaded after the CreateInstance returns.
| >>>>>
| >>>>Any idea of what could be the problem? Thanks a lot.
| >>>>>
| >>>>Here is the code segment I am using:
| >>>>>
| >>>>Object target;
| >>>>>
| >>>>Type oType = Type.GetTypeFromProgID("my.application", true);
| >>>>if (oType != null)
| >>>>>
| >>>>{
| >>>>>
| >>>> target = Activator.CreateInstance(oType);
| >>>>>
| >>>> if (target != null)
| >>>>>
| >>>> {
| >>>>>
| >>>> success = true;
| >>>>>
| >>>> }
| >>>>>
| >>>>}
| >>>>>
| >>>>>
| >>>>
| >>>>
| >>>
| >>>
| >>
| >>
| >
| >
|
|
Aug 5 '06 #7
The client is a simple C# class that invokes the COM server. The code
segment I included in my initial post is pretty much what I have now. I
need to get a valid reference to the COM server instance before I could do
anything more.

Yes, I use the same method to invoke Excel.Application or Word.Application.
Both work as expected.

Is there any tool that can be used to trace what is happening in the COM
interop layer?

Thanks.
jwang
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:Os**************@TK2MSFTNGP03.phx.gbl...
What kind of client are you talking about? Please post a simple client
that
illustrates the issue.
If the COM out-proc server ends it's because it stops running for a reason
known by the server not because of the client.
What happens if you create an instance of say Excel or Word from the same
client?

Willy.


"jwang" <jw***@newsgroups.nospamwrote in message
news:OX****************@TK2MSFTNGP06.phx.gbl...
|I have been calling the application in VB6 suing CreateObject(). It
always
| works as expected.
|
| I do not explicitly set the thread. Is that something I should do? I
just
| attempt to write a C# class that invokes that COM server.
|
| It seems that the reference to the COM server is lost when
CreateInstnace
| returns. Just do not know what has caused that.
|
| Thanks.
| jwang
|
|
|
|
|
| "Phil Wilson" <pd*******@nospam.cox.netwrote in message
| news:%2****************@TK2MSFTNGP06.phx.gbl...
| Is it possible that the managed object is being garbage collected and
| releasing references? Then the COM server just goes away.
| --
| Phil Wilson
| [Microsoft MVP-Windows Installer]
| "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
wrote
| in message news:O0**************@TK2MSFTNGP06.phx.gbl...
| >jwang,
| >>
| > This does not indicate an issue with .NET, but rather, the COM
server
| >(which is out of process) is being shut down.
| >>
| > If you try and create the object through say, vb script, do you
get
| >the same result?
| >>
| > Also, what do you have the ApartmentState set to on your thread?
| >>
| >>
| >--
| > - Nicholas Paldino [.NET/C# MVP]
| > - mv*@spam.guard.caspershouse.com
| >>
| >"jwang" <jw***@newsgroups.nospamwrote in message
| >news:On****************@TK2MSFTNGP03.phx.gbl...
| >>Nicholas,
| >>Thanks for responding to my question.
| >>>
| >>CreateInstance does not throw an exception, and it returns a
| >>System._ComObject. The COM component I try to invoke is a
| >>out-of-process component. From the Task Manager, I can see it was
| >>created and then went away. (I used the same method on
| >>Excel.Application, it works fine.)
| >>>
| >>Also, I try with ComImport to explicitly import the type, and then
use
| >>new to instantiate the component, but get the same problem.
| >>>
| >>jwang
| >>>
| >>>
| >>"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
wrote
| >>in message news:OO**************@TK2MSFTNGP05.phx.gbl...
| >>>jwang,
| >>>>
| >>> Either CreateInstance should throw, or return a value. What is
the
| >>>exception that is being thrown? I doubt it is
NullReferenceException.
| >>>>
| >>>>
| >>>--
| >>> - Nicholas Paldino [.NET/C# MVP]
| >>> - mv*@spam.guard.caspershouse.com
| >>>>
| >>>"jwang" <jw***@newsgroups.nospamwrote in message
| >>>news:%2****************@TK2MSFTNGP06.phx.gbl. ..
| >>>>>I am trying to instantiate a COM component in C# via late binding.
The
| >>>>>component appears to be launched, then it automatically gets
unloaded.
| >>>>>That is, the instance is unloaded after the CreateInstance returns.
| >>>>>
| >>>>Any idea of what could be the problem? Thanks a lot.
| >>>>>
| >>>>Here is the code segment I am using:
| >>>>>
| >>>>Object target;
| >>>>>
| >>>>Type oType = Type.GetTypeFromProgID("my.application", true);
| >>>>if (oType != null)
| >>>>>
| >>>>{
| >>>>>
| >>>> target = Activator.CreateInstance(oType);
| >>>>>
| >>>> if (target != null)
| >>>>>
| >>>> {
| >>>>>
| >>>> success = true;
| >>>>>
| >>>> }
| >>>>>
| >>>>}
| >>>>>
| >>>>>
| >>>>
| >>>>
| >>>
| >>>
| >>
| >>
| >
| >
|
|


Aug 6 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class...
2
by: Blake | last post by:
I'm using late binding to create Outlook email from an Access2K database. I am not referencing the Microsoft Office 9.0 Object Library nor the Microsoft Outlook 9.0 Object Library. Instead, I have...
1
by: Blake | last post by:
I'm using late binding to create Outlook email from an Access2K database. I am not referencing the Microsoft Office 9.0 Object Library nor the Microsoft Outlook 9.0 Object Library. Instead, I have...
7
by: Bob Darlington | last post by:
I'm using Access 2002 to try to open Outlook 2002 (late binding) using: Dim objOutlook As Object Set objOutlook = CreateObject("Outlook.Application") I get the above error if Outlook is closed...
1
by: jeanfor2 | last post by:
I am trying to do a late binding with a registered COM+ component and I am getting the following error when creating the instance. Below is the error I asm getting...Any idea? An unhandled...
1
by: jokolee | last post by:
i was using component AxSHDocVw.AxWebBrowser,,but i rather confuces because when i write AxWebBrowser1.Document. the next option is Gettype function,,,nothing else...... But when i write...
1
by: Rocio | last post by:
I have a windows app. written in VB6, now we need to expose some of its classes through a web service. I am only able to expose the classes using late binding becasue that's the way the original...
30
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
1
by: Igor Ladnik | last post by:
We are dealing with .NET server component and COM clients written with VB6 and VBScript. And there are some problems we faced (please see code below). 1. Managed type System Drawing.Color is...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.