1
votes

I have a VB.NET assembly that I have registered for Interop. I am using a class in this assembly in my VB6 projects.

In an existing VB6 project I added a reference to the type library and run the following code:

Dim vizDataSingleton As Vizual_Data.Singleton
Set vizDataSingleton = New Vizual_Data.Singleton

The second line errors "Run-time error 430: Class does not support Automation or does not support expected interface"

However if I start a blank VB6 project and add the reference, the exact same code works fine.

I checked the reference to the tlb in the vbp file and they are both identical.

Reference=*\G{BDB20DDF-D3B7-4484-8950-35D67DED45EC}#4.2#0#..\Vizual.Data\Vizual.Data\bin\Debug\Vizual.Data.tlb#VMS Data Structure Library

I tried using late binding as well:

Set vizDataSingleton = CreateObject("Vizual.Data.Singleton")

This errors in the existing project with "Type mismatch" but again works in the new project

Any ideas why this fails in one project but works in another?

1
Are you properly exposing an explicit ComInterfaceType.InterfaceIsIDispatch interface on your class (or at least, a ClassInterfaceType.AutoDispatch class interface)? msdn.microsoft.com/en-us/library/…noseratio
Clearly you are looking for an outlandish explanation. Seeing "Type mismatch" when you late-bind is certainly outlandish. A .NET exception would be one explanation, having the VB6 code run on a non-STA thread is another. Be sure to use the managed debugger to troubleshoot this, set VB6.exe as the start program. Add some debugging code so you can inspect the value of Thread.CurrentThread.GetApartmentState()Hans Passant
@Noseratio - the class is declared <ClassInterface(ClassInterfaceType.AutoDual)> with the COM Guids ClassId, InterfaceId and EventsId declared as Const inside the classMatt Wilko
@HansPassant - If I start from VS2012 and specify to run VB6.exe at startup, when I open the same project it does not fail (either early or late binding)Matt Wilko
Bummer. Well, keep looking for an outlandish explanation. Use SysInterals' ProcMon next and compare.Hans Passant

1 Answers

0
votes

I found the cause of this error in the end.

I had another .NET Interop assembly (Vizual_Lib) that was dependant on the original .NET assembly (Vizual_Data).

In the VB6 application that failed it was referencing both of these, but my new application only referenced Vizual_Data. Recompiling Vizual_Lib solved the issue.

This was a strange error was the failure happened when using the Vizual_Data class not the other Vizual_Lib class.