JBurace
JBurace

Reputation: 5633

InvalidCastException: Unable to cast COM object of type x to interface type y

I have some C# code written on machine #1 using Visual C# Express 2010. The code is dependent on some COM objects that are registered DLLs. It compiles and runs fine on machine #1. The COM objects are installed from a program called BostonWorkstation, which is installed on machines #1 and #2.



When I try to run that program (compiled on machine 1) on machine #2 which also has the same exact registered DLLs, but the program fails to run. I also tried running it on machine #3, which doesn't even have the DLLs and that gets a different error as expected.

The runtime error on machine 2:

1 Unable to load BostonWorkstation, error: System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'BostonWorkStation70.BostonWorkStation'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{8C8144EF-ADB7-48FD-A5BB-6E55B8382B3E}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). at TestBWS.LoginForm() in C:\Documents and Settings\user\My Documents\Visual Studio 2010\Projects\project1\TestBWS\CodeFile1.cs:line 67

(The Visual Studio folder reference is just the compile time path)

Checking the registry on machine 1 I found this:

HKEY_CLASSES_ROOT\Interface{8C8144EF-ADB7-48FD-A5BB-6E55B8382B3E}

with a default REG_SZ value of BostonWorkStation

The code:

    using BostonWorkStation70; //line 1

    ...

    try
    {
        bwsLogin = new BostonWorkStation(); //line 67
    }
    catch (Exception e)
    {
        Console.WriteLine("1 Unable to load BostonWorkstation, error: " + e);
        System.Console.ReadLine(); //pause the debug window
        return false;
    }

I have tried running ProcMon to compare the machines Process logs, but there are thousands of entries for just this program and I'm not seeing any missing references offhand. I ran a compare, but a successful Process log has 5x as many lines.

From what I understand, running the program on machine 2 has it creating the BWS object as a generic System.__ComObject (instead of BostonWorkStation70.BostonWorkStation) and I don't know why. The DLLs etc are definitely correct on machine 2, otherwise I'd be getting that Class not registered error on runtime.

Why will the compiled program not run on machine 2? All the dependent COMs/DLLs are on it.

Upvotes: 1

Views: 4412

Answers (3)

quixver
quixver

Reputation: 574

If the BostonWorkstation components are unmanaged - open them up in dependency walker to make sure that all their dependent dlls are present.

Odds are they are unmanaged components and make use of the MSVCRT 10. In which case you will need to install the VS 2010 CRT on machine 2.

Upvotes: 0

Sergii Kudriavtsev
Sergii Kudriavtsev

Reputation: 10532

Have you registered your COM object class from the library using regsvr32.exe on second machine?

To check that I'd search the registry on first and second machines looking for all possible {8C8144EF-ADB7-48FD-A5BB-6E55B8382B3E} string entries. If search results are different then it's probably the case.

Upvotes: 0

Jay
Jay

Reputation: 303

if that error message is coming from machine #2, the one you said "Visual C# 2010 Express not installed."

why is it running from the default visual studio projects folder?

C:\Documents and Settings\user\My Documents\Visual Studio 2010\Projects\project1\TestBWS\CodeFile1.cs:line 67

You may have other problems....

Upvotes: 1

Related Questions