COM API Erroring for C# program

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
HauptmannEck
Posts: 10
Joined: 24. Oct 2013, 20:35

COM API Erroring for C# program

Post by HauptmannEck »

Hello,
I am building a system for switching snapshots remotely. I am using a WCF web service as my base. The code so far is simple

Code: Select all

            var vBox = new VirtualBoxClass();
            Session session = new SessionClass();
            var vm = vBox.FindMachine("TestMachine");
            vm.LockMachine(session, LockType.LockType_Write);
            var console = session.Console;
            if (value == 7)
            {
                var off07Snap = vm.FindSnapshot("Office 2007");
                console.RestoreSnapshot(off07Snap);
            }
            else
            {
                var off10Snap = vm.FindSnapshot("Office 2010");
                console.RestoreSnapshot(off10Snap);
            }
I am referencing the VBoxC.DLL from my VirtualBox folder. My computer is a Windows 7 x64.
I have tried changing the Build Platform target to both x86 and x64.

When I use x86 the program starts and runs until it hits

Code: Select all

Session session = new SessionClass();
then errors while looking for VBoxRT-x86.dll (which does not exsist only VBoxRT.dll):
{"Retrieving the COM class factory for component with CLSID {3C02F46D-C9D2-4F11-A384-53F0CF917214} failed due to the following error: 8007007e The specified module could not be found. (Exception from HRESULT: 0x8007007E).":null}
if I switch it to x64 then the program doesn't even start with error:
Could not load file or assembly 'Interop.VirtualBox' or one of its dependencies. An attempt was made to load a program with an incorrect format.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
It seems to be an issue with my setup as it doesnt seem others have the same problems as me. any help you can give would be great.
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: COM API Erroring for C# program

Post by noteirak »

I personally have no experience whatsoever with C# and Virtualbox, so I won't be of any help here on what the requierments are.
Hopefully, one of the devs will look at this post and have some kind of answer for you.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Magnus Madsen
Posts: 22
Joined: 11. Jun 2013, 08:35
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: WinXP, WinVista, Win7, Win8

Re: COM API Erroring for C# program

Post by Magnus Madsen »

Hi HauptmannEck,

My experience with using the VirtualBox API with C# / Visual Studio is that the default interop-handler is not suitable for properly creating an interop DLL.

Please see my reply here: viewtopic.php?f=34&t=55033#p258866 as it details how to manually create an interop DLL.

I've created a new version for VirtualBox 4.3 if you wish to use mine: https://dl.dropboxusercontent.com/u/108 ... om.dll.zip
HauptmannEck
Posts: 10
Joined: 24. Oct 2013, 20:35

Re: COM API Erroring for C# program

Post by HauptmannEck »

Magnus Madsen wrote:Hi HauptmannEck,

My experience with using the VirtualBox API with C# / Visual Studio is that the default interop-handler is not suitable for properly creating an interop DLL.

Please see my reply here: viewtopic.php?f=34&t=55033#p258866 as it details how to manually create an interop DLL.

I've created a new version for VirtualBox 4.3 if you wish to use mine: https://dl.dropboxusercontent.com/u/108 ... om.dll.zip
Thanks for the responses,
I have tried your DLL, but the same issue persists. Something with how my computer is setup seems to be the issue, so this might not be solvable at this time. :(
Magnus Madsen
Posts: 22
Joined: 11. Jun 2013, 08:35
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: WinXP, WinVista, Win7, Win8

Re: COM API Erroring for C# program

Post by Magnus Madsen »

HauptmannEck wrote:Thanks for the responses,
I have tried your DLL, but the same issue persists. Something with how my computer is setup seems to be the issue, so this might not be solvable at this time. :(
The second error you receive is odd - the interop DLL should not be tied to 32- or 64-bit assembly versions. I am using the same file successfully with both x86 and x64 versions of my application.

Have you disabled "Embed interop types" in the properties for the reference to the Interop DLL?
HauptmannEck
Posts: 10
Joined: 24. Oct 2013, 20:35

Re: COM API Erroring for C# program

Post by HauptmannEck »

Magnus Madsen wrote: The second error you receive is odd - the interop DLL should not be tied to 32- or 64-bit assembly versions. I am using the same file successfully with both x86 and x64 versions of my application.

Have you disabled "Embed interop types" in the properties for the reference to the Interop DLL?
I agree it is an odd error, but the "Embed interop types" is set to false. I cant even build if it is not false.
HauptmannEck
Posts: 10
Joined: 24. Oct 2013, 20:35

Re: COM API Erroring for C# program

Post by HauptmannEck »

Well it seems the issue is the fact I was building a WCF project. Virtual Box cannot work very well in a WCF hosted by IIS i guess the IIS stops anything that could have host user interaction like VM windows, which is what Session initializing must trigger. I am not testing a WPF project and the x64 setting is working perfectly. x86 still does the same error looking for VboxRT-x86.DLL, but that doesnt bother me anymore.

Im trying to think of a way to work around the IIS issue, does anyone who worked on C# virtual box project have a way to have a web service interface which calls something else to start and stop VMs?
Magnus Madsen
Posts: 22
Joined: 11. Jun 2013, 08:35
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: WinXP, WinVista, Win7, Win8

Re: COM API Erroring for C# program

Post by Magnus Madsen »

I'm sorry to say I have only been working on client applications, so the problem is not familiar to me.

Perhaps you could try to see if you can successfully control the Snapshots from a Windows Service application? If that works, you can just create a communication between your service and the WCF application.
Post Reply