Late binding to access COM+

G

Guest

Hi all,

I have two objects in my COM+ that I can't add the references to my project.
It has to use late binding in C#. For my applications in vb.net, I can solve
the problem using the code below. However, the late binding should be in C#.
How can I solve the problem?

Dim o As Object
Dim rs As ADODB.Recordset / databaset

o = CreateObject("Component.Class1")
rs = o.Load("SELECT * FROM Customer")
o = Nothing

How can I apply this code to C#?

Thanks in advance,
Wonder
 
N

Nicholas Paldino [.NET/C# MVP]

Wonder,

The proper way to do this is to create an interface that your COM+ class
implements. Then, you would create the instance as you would normally
(through CreateInstance) and then cast it to the interface.

You shouldn't be making late bound calls like this. Interfaces are an
easy way to prevent you from having to do that. The key is defining the
interface in an assembly separate from the implementation (the
implementation is what is registered).

Hope this helps.
 
G

Guest

Thanks for the help. Could you help me with your explanation giving me an
example of that?

Thanks,


Nicholas Paldino said:
Wonder,

The proper way to do this is to create an interface that your COM+ class
implements. Then, you would create the instance as you would normally
(through CreateInstance) and then cast it to the interface.

You shouldn't be making late bound calls like this. Interfaces are an
easy way to prevent you from having to do that. The key is defining the
interface in an assembly separate from the implementation (the
implementation is what is registered).

Hope this helps.


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

Wonder said:
Hi all,

I have two objects in my COM+ that I can't add the references to my
project.
It has to use late binding in C#. For my applications in vb.net, I can
solve
the problem using the code below. However, the late binding should be in
C#.
How can I solve the problem?

Dim o As Object
Dim rs As ADODB.Recordset / databaset

o = CreateObject("Component.Class1")
rs = o.Load("SELECT * FROM Customer")
o = Nothing

How can I apply this code to C#?

Thanks in advance,
Wonder
 

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