C# - Com Interop - ClassInterfaceType.None

G

Guest

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?
 
T

Truong Hong Thi

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
 
G

Guest

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.
 
G

Guest

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.
 
T

Truong Hong Thi

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
 
G

Guest

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?
 
T

Truong Hong Thi

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
 
G

Guest

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?
 
G

Guest

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?
 
E

ewm

/codebase is for private assemblies - ones that are reserved for use by a
single exe. If you want your assembly accessible to multiple others, you must
register in the GAC.
 

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

Similar Threads


Top