0

I have an exe file “ClarityII.exe” supplied by the vendor of a weather monitoring product (Boltwood Cloud Sensor II). The app provides a GUI for displaying and controlling the sensor state, and provides a COM interface to integrate with other software. So far I’m not getting any help from the vendor. I believe it was written in VB6.

I’m trying to make use of the COM interface from a VS2013 .NET 4.5.1 C# program. The vendor supplied a very simple VB6 test ap which works fine.

I have added the required clarityII reference to my C# project. The reduced code below compiles, and when I run it the vendor’s GUI is displayed as expected, but I get the exception below.

The exception occurs when cloudII is created using new:

An unhandled exception of type 'System.InvalidCastException' occurred in Interop1.exe

Additional information: Unable to cast COM object of type 'System.__ComObject' to interface type 'ClarityII.CloudSensorII'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{ XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX }' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

What is likely to be causing this error? I thought the interop was done for me by the compiler automatically producing the wrapper Interop.ClarityII.dll?

I have the following skeleton

using System;
using ClarityII;

class MainClass 
{
  [STAThread]
  public static void Main(string[] args) 
  { 
    ClarityII.CloudSensorII cloudII;
    cloudII = new ClarityII.CloudSensorII();
  }
}

PS edit: I just ran my C# program on another PC with the same ClarityII.exe installed. On that PC there is no exception when I instantiate the COM object. I can also access properties OK. Any ideas what could be broken on my dev PC?

Darren M
  • 3
  • 3
  • 1
    Obfuscating a number in an exception message like that is an incredibly dumb idea. Not only is it pointless, it casts a heavy doubt on what else you are not telling us. There is no explanation for this exception with the provided info, use the other machine. – Hans Passant Nov 07 '16 at 07:44
  • I'm a beginner here. In my searches I had seen others do it so I thought maybe it revealed something I shouldn't. I will take a diversion to educate myself on the origin of each part of the IID. – Darren M Nov 07 '16 at 12:37
  • Interface IDs (the GUID you obscured) are not confidential information. They are simply a unique number the vendor assigned to the interface so that nobody else would confuse it with some other interface from some other vendor. – Euro Micelli Nov 08 '16 at 01:16

1 Answers1

1

My guess... Check your ClarityII type library on your Dev machine to make sure it is registered correctly. And, especially since it is EXE to EXE COM, check to see if the interface (CloudSensorII ?) is registered on your Dev machine. Since it is EXE to EXE, there will be marshalling. I have experienced problems in the past using Office interfaces when Office didn't register correctly on a host machine and did not register some interfaces. In those cases, I would sometimes get E_NOINTERFACE errors, IIRC.

There is a registry subkey HKEY_CLASSES_ROOT\Interface

and there is one for 32-bits on 64-bit machines:

HKEY_CLASSES_ROOT\Wow6432Node\Interface

Check on the machine that is working and compare with the one that is not.

Joseph Willcoxson
  • 5,853
  • 1
  • 15
  • 29
  • Great suggestion - HKEY_CLASSES_ROOT\Wow6432Node\Interface was indeed missing keys on my Dev machine. Reinstalling the COM exe package did not fix it - manually adding the keys by exporting them from the working PC to the Dev PC solved the problem. My program is now working perfectly. Thanks! – Darren M Nov 08 '16 at 03:13