Page 1 of 1

Using MSCOM API in C#

Posted: 4. Nov 2010, 20:19
by animus
I've been trying to compile a simple app to pause/unpause a VM based on my Laptop's accelerometer. My laptop parks the HDD when the acceleration exceeds a threshold, and if it stays parked for some time, VBox tends to make the VHD controller stop responding, wreaking havoc. So, I'm making an app that monitors this acceleration and pauses the VM when the HDD is parked.

However, when I try to get it to actually interact with a VM, I get an error on launch:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Additional information: Retrieving the COM class factory for component with CLSID {3C02F46D-C9D2-4F11-A384-53F0CF917214} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
This occurs at this portion of the code:

Code: Select all

Session Sess = new Session();
I've tried using an ISESSION instead, but I have no way to initialize it (and the function refuses to take it uninitialized), and casting is useless as well. Any Idea what to do?

Re: Using MSCOM API in C#

Posted: 7. Nov 2010, 23:21
by Duke
I'm having the same problem here.
i suppose the issue is caused by some sort of impatibility or misconfiguration as i'm running Virtualbox on a 64 bit system while the tpl seems to be 32 bit.

i'm not sure this is the cause and anyway i have not ofund a solution yet :(
any progress from you?

Re: Using MSCOM API in C#

Posted: 8. Nov 2010, 11:36
by Duke
I confirm that on Windows XP (32 Bit of course) the exact same code works perfectly

Session s = new Session();

or

Session s = new Session();

doesn't thows any exception and instead creates a valid session i can inspect and use normally.

this enforce my supposition that there is something wrong in the registration of the VBoxC.dll that's apparently is the one that contains the factory for the Session object, or in the TPL defintion when the host system is 64 bit.

that's two times strange if you consider that the code

var vbox = new VirtualBoxClass();

works well both on 64 and 32 bit windows OS... and it is exposed by the same TPL.

In fact it's factory appears to be contained in a different file (VBoxsvc.exe), so this may be the difference...

Unfortunately i'm not a great expert in .NET-COM interaction and at the moment i don't know how to solve this issue.

I'm also considering that the otehr frontends works well on my Windows 7 64 bits, so there should be a way to make this work... obviously the other frontends are not .NET so it is probably all the marshalling-unmarshalling things that becomes brokens somewhere :(

that's very frustrating :(

Re: Using MSCOM API in C#

Posted: 8. Nov 2010, 21:38
by amirt
Hi,

this issue is related to 64/32 bit.

compile your code for X64 to solve this.

this happens because on 64bit platform vbox fails to register the 32bit version of the Session object(i dont know why)
however the VirtualBox object exists under both 32/64 bit.

comfirmed fixing this issue today with Win7 64bit / VS2010.

Amir.

Re: Using MSCOM API in C#

Posted: 9. Nov 2010, 01:43
by Duke
Amirt: THANKS A LOT!
that's really solved the issue!

i had another little fight with the test project (i had to set in the host tab of the test setting to run the test in 64 bit too) but that was a lot easier knowing how to solve the other issue for wich you have provided the solution!

thanks again!!!
now i'm again happy :)