Cannot use IDisplay. It's null

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
JustCoder
Posts: 3
Joined: 6. Mar 2013, 22:20

Cannot use IDisplay. It's null

Post by JustCoder »

Hi all!

I wrote a virtual box frontend in C# using com api. I haven't touched my code for about a year. During that year I've moved to a laptop from pc. Last time run my code it worked fine. Now I cannot access IDisplay because it's null;
here is my code:

Code: Select all

var vb = new VirtualBoxClass();
_machine = vb.FindMachine(machineName);

var monitors = _machine.MonitorCount;

Monitors = new MMFFrameBuffer[monitors];
for (byte i = 0; i < monitors; i++)
{
    var name = string.Format("monitor{0}", i + 1);
    Monitors[i] = MMFFrameBuffer.CreateNew(name);
}

_session = new SessionClass();
_machine.LockMachine(_session, LockType.LockType_Shared);

for (int i = 0; i < MonitorsCount; i++)
{
    _session.Console.Display.SetFramebuffer((uint) i, Monitors[i]);
}
My program fails on the line where I'm trying to set framebuffer. I get NullreferenceException: _session.Console.Display is null.
My current version of Vbox is the latest: 4.2.8 r83876. I can't remember the exact version on which my code ran correctly. I can only say It was the latest one about 1 year ago. Host OS is Win7 pro x64 (same as it was on my previous PC)

I'm completely clueless about my issue. Any help would be highly appreciated!
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: Cannot use IDisplay. It's null

Post by noteirak »

Which API version do you use to connect?
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
JustCoder
Posts: 3
Joined: 6. Mar 2013, 22:20

Re: Cannot use IDisplay. It's null

Post by JustCoder »

Hi noteirak!

Thanks for your reply. I don't understand what you mean by version of api. Here is how I did my project:
1) Installed the most recent version of virtual box: 4.2.8 r83876
2) Open my old Visual Studio solution with the code from my OP.
3) Removed old VirtualBox reference.
4) Added reference to "VirtualBoxType Library" under "COM" tab. The version of that library is 1.3
5) Built, Ran.

The same code worked fine a year ago (with old version of VirtualBox) Unfortunately I can't remember the version, but it was the most recent one at that time.

UPD:
I've just checked my project files. Com references are identical in my backed up version and the current one. Weird...
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: Cannot use IDisplay. It's null

Post by noteirak »

Your code seems right.

I have never used Virtualbox in Visual Studio, so I am not sure what the issue is on this one.
IMO the best place would be to go on the Dev Mailing List, they would have more answers for you there
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
JustCoder
Posts: 3
Joined: 6. Mar 2013, 22:20

Re: Cannot use IDisplay. It's null

Post by JustCoder »

Hi, noteirak

Thank you for your help. I've actually found the solution in dev mailing list.
Hi,

VirtualBox 4.2 has introduced a new lock type for VM frontends: LockType.LockType_VM. You have to use this lock type, otherwise the Console related objects are not initialized.

Ivo
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: Cannot use IDisplay. It's null

Post by noteirak »

Good catch. Never using processes that run the VM, I wasn't aware of that one.
Thank you for posting the resolution!
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply