363,924 Members | 2598 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

C# - Com Interop - ClassInterfaceType.None

HL
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


Truong Hong Thi
P: n/a
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

Nov 25 '05 #2

HL
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:
[color=blue]
> 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
>
>[/color]
Nov 25 '05 #3

HL
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:
[color=blue]
> 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
>
>[/color]
Nov 25 '05 #4

Truong Hong Thi
P: n/a
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

Nov 25 '05 #5

HL
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:
[color=blue]
> 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
>
>[/color]
Nov 25 '05 #6

Truong Hong Thi
P: n/a
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

Nov 25 '05 #7

HL
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:
[color=blue]
> 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
>
>[/color]
Nov 25 '05 #8

Willy Denoyette [MVP]
P: n/a
Willy Denoyette [MVP]
Use the /codebase option when running regasm.

Willy.

"HL" <HL@discussions.microsoft.com> wrote in message
news:166EE0A1-2CB5-4FBC-BDC4-8EAFC5C447BF@microsoft.com...[color=blue]
> 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:
>[color=green]
>> 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
>>
>>[/color][/color]


Nov 25 '05 #9

HL
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:
[color=blue]
> Use the /codebase option when running regasm.
>
> Willy.
>
> "HL" <HL@discussions.microsoft.com> wrote in message
> news:166EE0A1-2CB5-4FBC-BDC4-8EAFC5C447BF@microsoft.com...[color=green]
> > 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:
> >[color=darkred]
> >> 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
> >>
> >>[/color][/color]
>
>
>[/color]
Nov 30 '05 #10

Post your reply

Help answer this question



Didn't find the answer to your C# / C Sharp question?

You can also browse similar questions: C# / C Sharp