locked
Interop Error - "Type Mismatch" RRS feed

  • Question

  • Hi,

    I am currently working on migrating a large VB6 application to VB2005. We are using interop and reverse interop to build a hybrid application as we migrate components to .net.

    I am having a problem when I am calling a VB6 component from one of the .net components (I am running both the IDEs so I am able to break into the code on either side). The VB6 DLL has a private member which is a .NET object (one of our migrated DLLs), this is set via a public property which I am doing in .net. When I try and set the member in .net using the property (using the following code):

    Code:
    clsClient.DatabaseManager = clsSecurity.DatabaseManager

    (clsClient is the VB6 DLL and clsSecurity is the .NET DLL)

    I get the error "Type Mismatch". I had a look and I saw that although clsSecurity.DatabaseManager was defined as the .net DLL, the VB6 clsClient.DatabaseManager was defined as Object. Although I wasn't sure why this should cause a type mismatch I changed the code to have it early bound (defined as the .NET DLL type).

    However because the VB6 application is part of a massive project group, I am unable to compile the whole thing on my machine - therefore my question is this. When I reference the COM DLL from the .net assembly I choose the compiled DLL, which creates the runtime callable wrapper for that DLL. When I make changes to the VB6 DLL in the IDE I assume that the .NET Assembly cannot see the changes I have made because it is referencing the compiled DLL (i.e. the .NET DLL still sees clsClient.DatabaseManager as being defined as Object rather than being early bound). Is this right? And is there any way to have the .NET see the changes I have made to the VB6 DLL without creating a compiled DLL? I also noticed that the VB6 app only had Property Get and Property Let (no Property Set) - I know that Let is not supported in .NET so I made a change and added Property Set in the VB6 DLL but again I cannot see these changes. I looked at the RCW for the VB6 DLL in ILDASM and it looked like a Property Set was created anyway, so I am not sure if this has an affect anyway?

    I am pretty confused and have probably got some of the above completely wrong! I am still not sure if this is why the type mismatch error is occurring but I think it must be something along these lines. Does anyone have any ideas?

    Thanks in advance.
    Monday, March 10, 2008 5:55 PM

Answers

  • Les9000,

     

    Based on your post, you are trying to set the unmanaged clsClient.DatabaseManager property to managed clsSecurity.DatabaseManager property and get "Type Mismatch" error message.

     

    When you are adding reference the unmanaged COM DLL , RCW (Runtime Callable Wrapper) is the particular type of proxy used in calling unmanaged component from .NET. There is Type Library Importer tool (tlbimp) that reads the metadata from a COM type library and creates a matching CLR assembly for calling the COM component. When you change something of COM DLL, I suggest you to use tlbimp with the /out option to create the matched RCW proxy like this: tlbimp unmanaged.dll /out:managed.dll

     

    Direct reference COM component is only suitable for a truly private component that does not need to be shared and be used in a single .NET project. Using TlbImp tool, you can sign the resulting assembly and place it in GAC and share among multiple projects.

     

    On the upgrade issue such as Property Set changes in VB.NET, I would like to provide you an article below:

     

    Migrate Your VB6 Code to VB.NET

     

    Hope that can provide you some idea.

    Wednesday, March 12, 2008 6:46 AM