PowerUp StackOverflowException

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

PowerUp StackOverflowException

Post by HauptmannEck »

I have a new issue so I made a new Topic.

I can get everything in my code to work until it hits the IConsole:PowerUp

Code: Select all

            var vmName = TextBox.Text;

            var vBox = new VirtualBoxClass();
            var vm = vBox.FindMachine(vmName);
            String[] arr;
            Session session = new SessionClass();
            vm.LockMachine(session, LockType.LockType_Write);
            var console = session.Console;

            var snap = vm.FindSnapshot("Base");
            var progressSnap = console.RestoreSnapshot(snap);
                progressSnap.WaitForCompletion(-1);

        --->var progStart = console.PowerUp();<---
            progStart.WaitForCompletion(5000);

            var state = vm.State.ToString();
            state = vm.SessionState.ToString();

            var progStop = console.PowerDown();
            progStop.WaitForCompletion(5000);
Then I get an error which terminates everything:

Code: Select all

An unhandled exception of type 'System.StackOverflowException' occurred in VBoxWPF.exe
I can run a LaunchVMProcess and it starts correctly, but I need to restore the snapshot "Base" first.

Another issue I am having is with the vBoxManager.exe.
when I try to copyto in the command line it always errors no matter what the destination is:

Code: Select all

VBoxManage.exe: error: Querying directory existence \"C:\\\" failed: VERR_TIMEOUT.\r\n
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: PowerUp StackOverflowException

Post by Magnus Madsen »

Hi Hauptmann,

You are using an incorrect method for starting up the VM - although I'm not sure that is what is causing the overflow, it is probably the cause.

Using:

Code: Select all

vm.LockMachine(session, LockType.LockType_Write);
and

Code: Select all

var progStart = console.PowerUp();
are only used if you wish to create your own front-end for hosting the Virtual Machine process.
If you only wish to start up a VM in a standard process (with GUI or without), you should use the LockType.LockType_Shared lock type and the launchVMProcess function for starting up the VM instead.

I'll just quote this from the documentation for the console.PowerUp command:
Note: This method is only useful for front-ends that want to actually execute virtual
machines in their own process (like the VirtualBox or VBoxSDL front-ends). Unless you
are intending to write such a front-end, do not call this method. If you simply want to
start virtual machine execution using one of the existing front-ends (for example the
VirtualBox GUI or headless server), use IMachine::launchVMProcess() instead; these
front-ends will power up the machine automatically for you.
I've modified your code to the below, which should start up the selected VM in a normal GUI process:

Code: Select all

            var vBox = new VirtualBoxClass();
            var vm = vBox.FindMachine(vmName);
            String[] arr;
            Session session = new SessionClass();
            vm.LockMachine(session, LockType.LockType_Shared);
            var console = session.Console;

            var snap = vm.FindSnapshot("Base");
            var progressSnap = console.RestoreSnapshot(snap);
                progressSnap.WaitForCompletion(-1);

            var progStart = console.Machine.LaunchVMProcess(session, "gui", "");
            progStart.WaitForCompletion(5000);

            var state = vm.State.ToString();
            state = vm.SessionState.ToString();
The second argument to LaunchVMProcess specifies in what front-end the VM should be started. The default is "gui". "headless" will start the VM in the background, and "sdl" is a simple display that cannot be interacted with. The documentation will provide more information on this.
HauptmannEck
Posts: 10
Joined: 24. Oct 2013, 20:35

Re: PowerUp StackOverflowException

Post by HauptmannEck »

When I try to use the code you posted i get the COMException:

Code: Select all

The given session is busy
on the line

Code: Select all

var progStart = console.Machine.LaunchVMProcess(session, "gui", "");
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: PowerUp StackOverflowException

Post by Magnus Madsen »

Ah, sorry I had made an error.

When using the LaunchVMProcess, you should not use a session that has been locked.
You need to lock a session to restore the snapshot you want to use, but you'll need to unlock the session afterwards before you can start the VM.

Code: Select all

            var vm = vBox.FindMachine(vmName);
            String[] arr;
            Session session = new SessionClass();
            vm.LockMachine(session, LockType.LockType_Shared);
            var console = session.Console;

            var snap = vm.FindSnapshot("Base");
            var progressSnap = console.RestoreSnapshot(snap);
            progressSnap.WaitForCompletion(-1);

            session.UnlockMachine();

            var progStart = vm.LaunchVMProcess(session, "gui", "");
            progStart.WaitForCompletion(5000);

            var state = vm.State.ToString();
            state = vm.SessionState.ToString();
HauptmannEck
Posts: 10
Joined: 24. Oct 2013, 20:35

Re: PowerUp StackOverflowException

Post by HauptmannEck »

SWEET that worked great!!!

Thanks for all your help
Post Reply