Note that there are some explanatory texts on larger screens.

plurals
  1. POInvalidCastException: Unable to cast COM object of type x to interface type y
    primarykey
    data
    text
    <p>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.</p> <ul> <li>Machine 1: <ul> <li>Code written on.</li> <li>Visual C# 2010 Express installed.</li> <li>The "BWS" DLLs are registered.</li> <li>The program runs just fine.</li> <li>Has .NET versions: v4.0, v4, v3.5, v3.0, v2.0</li> <li>32bit</li> </ul></li> </ul> <p><br /></p> <ul> <li>Machine 2: <ul> <li>The "BWS" DLLs are registered.</li> <li>The program errors with <code>System.InvalidCastException</code> (below).</li> <li>Visual C# 2010 Express not installed.</li> <li>Has .NET versions: v4, v3.5, v3.0, v2.0, v1.1</li> <li>32bit</li> </ul></li> </ul> <p><br /></p> <ul> <li>Machine 3: <ul> <li>The "BWS" DLLs are not registered.</li> <li>Visual C# 2010 Express installed.</li> <li>The program errors (as expected) with: <code>System.Runtime.InteropServices.COMException (...): Retrieving the COM class factory for component with CLSID {...} failed due to the following error: 80040154 Class not registered (...)</code></li> <li>32bit</li> </ul></li> </ul> <p>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.</p> <p>The runtime error on machine 2:</p> <blockquote> <p>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</p> </blockquote> <p>(The Visual Studio folder reference is just the compile time path)</p> <p>Checking the registry on machine 1 I found this:</p> <blockquote> <p>HKEY_CLASSES_ROOT\Interface{8C8144EF-ADB7-48FD-A5BB-6E55B8382B3E}</p> </blockquote> <p>with a default REG_SZ value of <code>BostonWorkStation</code></p> <p>The code:</p> <pre><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; } </code></pre> <p>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.</p> <p>From what I understand, running the program on machine 2 has it creating the BWS object as a generic <code>System.__ComObject</code> (instead of <code>BostonWorkStation70.BostonWorkStation</code>) and I don't know why. The DLLs etc are definitely correct on machine 2, otherwise I'd be getting that <code>Class not registered</code> error on runtime.</p> <p>Why will the compiled program not run on machine 2? All the dependent COMs/DLLs are on it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload