By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,694 Members | 1,795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,694 IT Pros & Developers. It's quick & easy.

C# - Com Interop - ClassInterfaceType.None

P: n/a
HL
I want to use the services of a C# dll from a VB6 client. The C# dll has a
public method called "Add". In the C# dll, the class interface type applied
for the class is as follows:

[ClassInterface(ClassInterfaceType.None)]

The Com visible attribute for the type is set to true.
[ComVisible(true)]

I used RegAsm Utility to generate the Tlb file.

In the VB6 client, I set a reference to the tlb file. I create an instance
of the type as follows:

Dim Ret As Integer
Dim oSample As New Sample

The problem is that the intellisense does not show the Add method at all. It
only shows - Equals, GetHashCode, GetType and ToString.

Where am I going wrong?
Nov 25 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
It seems that your class does not implement any interface and regasm
exposes _Object as the default interface. To have Add shown with
intellisense, you need to declare an interface containing Add method,
and let your class extend it.

Thi
http://thith.blogspot.com

Nov 25 '05 #2

P: n/a
HL
Hi,

Thank you for the quick response.

As per your suggestion, I have now implemented an interface with the Method
Add.

In VB6, the Intellisense shows the method "Add" only (as I wanted).

But, the problem now is that the following statement gives an Automation
error.

oSample.Add();

The same method call works fine, when I call the Add method from a C# Test
Exe.

"Truong Hong Thi" wrote:
It seems that your class does not implement any interface and regasm
exposes _Object as the default interface. To have Add shown with
intellisense, you need to declare an interface containing Add method,
and let your class extend it.

Thi
http://thith.blogspot.com

Nov 25 '05 #3

P: n/a
HL

I tried the following method and still the same error.

An automation is thrown, when the C# Dll is created in the following manner.

Dim oSample as Sample
set oSample = new Sample()

The Automation error says "The System cannot find the file specified"
Run-time error - '2147024894(80070002).

Please Help.
"Truong Hong Thi" wrote:
It seems that your class does not implement any interface and regasm
exposes _Object as the default interface. To have Add shown with
intellisense, you need to declare an interface containing Add method,
and let your class extend it.

Thi
http://thith.blogspot.com

Nov 25 '05 #4

P: n/a
Hi, could you post more info:
What did the error say?
How complex is your add method?
And some more info if you think it is useful.

Thi

Nov 25 '05 #5

P: n/a
HL
Hi,

The Add method is just a test method and there is just a
Console.Writeline statement and nothing more.

Looks like the VB6 client is not able to locate the C# dll , because the
creation of the object itself is throwing an error. Am I missing something
else?

"Truong Hong Thi" wrote:
Hi, could you post more info:
What did the error say?
How complex is your add method?
And some more info if you think it is useful.

Thi

Nov 25 '05 #6

P: n/a
It complains that the DLL you compiled with C# is not found.
You can do one of the following:
- copy the DLL to VB installation folder (likely C:\Program
Files\Microsoft Visual Studio\VB98)
- copy DLL to OS system folder (e.g WinNT/System32)
- Copy the DLL file to the same folder as your VB DLL/EXE. This does
not work if you want to debug your code because you can only generate
VB DLL/EXE by File/Make XXX.... menu item.

It is annoying that VB6 does not support "Working Directory" project
property for debugging; otherwise you can set it to the folder
containning the C# DLL.

Hope it helps,
Thi - http://thith.blogspot.com

Nov 25 '05 #7

P: n/a
HL
Thanks a lot Thi. It works fine now.

Just one Doubt.
The Vb Exe should have located the path of the C# Dll from the registry and
executed. Why is it required to place the VB Exe in the same path as the C#
Dll?

"Truong Hong Thi" wrote:
It complains that the DLL you compiled with C# is not found.
You can do one of the following:
- copy the DLL to VB installation folder (likely C:\Program
Files\Microsoft Visual Studio\VB98)
- copy DLL to OS system folder (e.g WinNT/System32)
- Copy the DLL file to the same folder as your VB DLL/EXE. This does
not work if you want to debug your code because you can only generate
VB DLL/EXE by File/Make XXX.... menu item.

It is annoying that VB6 does not support "Working Directory" project
property for debugging; otherwise you can set it to the folder
containning the C# DLL.

Hope it helps,
Thi - http://thith.blogspot.com

Nov 25 '05 #8

P: n/a
Use the /codebase option when running regasm.

Willy.

"HL" <HL@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.com...
Thanks a lot Thi. It works fine now.

Just one Doubt.
The Vb Exe should have located the path of the C# Dll from the registry
and
executed. Why is it required to place the VB Exe in the same path as the
C#
Dll?

"Truong Hong Thi" wrote:
It complains that the DLL you compiled with C# is not found.
You can do one of the following:
- copy the DLL to VB installation folder (likely C:\Program
Files\Microsoft Visual Studio\VB98)
- copy DLL to OS system folder (e.g WinNT/System32)
- Copy the DLL file to the same folder as your VB DLL/EXE. This does
not work if you want to debug your code because you can only generate
VB DLL/EXE by File/Make XXX.... menu item.

It is annoying that VB6 does not support "Working Directory" project
property for debugging; otherwise you can set it to the folder
containning the C# DLL.

Hope it helps,
Thi - http://thith.blogspot.com

Nov 25 '05 #9

P: n/a
HL
Hi Willy,

What are the pros and cons of using the /Codebase option to make an
entry for the .NET assembly in the registry vis-a-vis placing the .NET
assembly (that is used by COM) in the GAC?

"Willy Denoyette [MVP]" wrote:
Use the /codebase option when running regasm.

Willy.

"HL" <HL@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.com...
Thanks a lot Thi. It works fine now.

Just one Doubt.
The Vb Exe should have located the path of the C# Dll from the registry
and
executed. Why is it required to place the VB Exe in the same path as the
C#
Dll?

"Truong Hong Thi" wrote:
It complains that the DLL you compiled with C# is not found.
You can do one of the following:
- copy the DLL to VB installation folder (likely C:\Program
Files\Microsoft Visual Studio\VB98)
- copy DLL to OS system folder (e.g WinNT/System32)
- Copy the DLL file to the same folder as your VB DLL/EXE. This does
not work if you want to debug your code because you can only generate
VB DLL/EXE by File/Make XXX.... menu item.

It is annoying that VB6 does not support "Working Directory" project
property for debugging; otherwise you can set it to the folder
containning the C# DLL.

Hope it helps,
Thi - http://thith.blogspot.com


Nov 30 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.