Confusion around VirtualBox CustomVideoModes in Windows

There are plenty of instances in online forums (eg here and here) of questions about setting CustomVideoModes in VirtualBox when running Windows as the client OS.

What is CustomVideoMode?

A CustomVideoMode is an additional screen resolution made available to the VirtualBox guest OS over and above those that are already present by default in VirtualBox.

The command to set a CustomVideoMode in VirtualBox is:

VBoxManage setextradata "VM Name" CustomVideoMode1 1920x1080x32

This command is run from your VirtualBox installation location in the host OS. The VM Name must be the name of your virtual machine, CustomVideoMode1 can change to CustomVideoMode2 etc to allow for additional extra modes, and the resolution part should be set to the resolutions you need.

What actually happens in Windows

This isn’t actually the proper way to deal with resolutions in Windows guests. Instead, the Guest Additions should be installed into the client OS, and then the option to use Auto-resize Guest Display will resize the guest to whatever size it’s containing window is at. In fact, if you use the above command to add custom video modes, and then look at the options in the display properties on the guest, then they won’t even be shown – usually there will just be the VirtualBox defaults plus whatever size the guest happens to have sized itself to at that moment.

In my recent experience however this isn’t the full story here. I often find that, on my running virtual machines, the auto-resize stops working, particularly after the host sleeps, or the number of monitors attached to the host changes (I use a laptop most of the time, and plug into a dock at home).

What’s going on?

VirtualBox Guest Additions installs a VirtualBox Display adapter driver – this is what handles the auto-resize for us. Unfortunately, I find that this crashes and gets disabled by the guest OS fairly frequently. I can see errors in my guest event log such as:

Display driver VBoxVideoW8 stopped responding and has been successfully disabled.

I suspect I’m getting this more than most as I’ve been running the preview builds of Windows 10 for quite a while in my guests, and my use of a laptop means that my display switches relatively often.

As the message says the VBoxVideoW8 driver is disabled. This is what stops the resizing from working. Instead we fallback to using the Microsoft Basic Display Driver, and we’re stuck with the original defaults. When the guest OS is rebooted the VirtualBox driver will usually work again, but rebooting is usually undesirable as our current workspace is lost. Alternatively we can try to reinitialize the VirtualBox driver by going through the Update driver dialogs and manually selecting the Oracle Corporation >> VirtualBox Device driver. Unfortunately I find that this tends to require a reboot to take effect anyway.

CustomVideoMode to the rescue

Helpfully, the Microsoft Basic Display Driver does pick up settings made using the CustomVideoMode. This means we can have a nice fallback when the VirtualBox driver stops. Adding our normal working resolutions lets us manually switch between then as required in the guest display properties dialog.

Therefore I tend to install my Windows VMs with the following two statements that cover my two main display resolutions:

VBoxManage setextradata "VM Name" CustomVideoMode1 1920x1080x32
VBoxManage setextradata "VM Name" CustomVideoMode2 1366x768x32

With these set, I can easily switch the guest to work nicely in full screen on whichever display I need without an annoying reboot or mis-sized guest.

CloudFlare DDNS updates

This blog is hosted on a Raspberry Pi under my TV at home. As is common with this scenario I have a dynamic WAN IP, updating intermittently at the whim of my ISP/router.

After a few attempts I’ve finally got a stable DDNS update that works with CloudFlare (having had trouble with various bits of ddclient+patches etc) in the form of some scripts that call curl against the Api directly. This seems nice and neat, and the scripts can be scheduled using cron.

I’ve posted the scripts used here. I’ll try to keep these updated as the CloudFlare Api changes (as I’ll have to to keep the site running!).

I’ve included the script required to download details of the dns records from CloudFlare, as this is required to get the rec_id value for the dns entry, which is then sent back for the update. My version of the main update script also maintains a simple log file of updates.

The repo is here, the update script is here
and the read script is here

A TinyIoC Bootstrapper

I really like the TinyIoC Inversion of Control Container. It’s nice and straight forward to use, it’s easily portable, and the auto registration feature does 99% of your work for you. In recent projects it has been an ideal choice, either because of the size of the project, or to introduce the concepts of DI to teams that weren’t already familiar with it.

With a little work though we can help it punch a little above its weight.

The sidekick to an IoC container is the Bootstrapper. A good bootstrapper can make DI a simple painless exercise that just works, so I thought I’d share mine. It started life with the DefaultNancyBootstrapper from the Nancy project and evolved from there.

It’s available and documented with examples on GitHub here, so I won’t go into it in depth, but I will cover the main aspects I wanted to solve.

Auto Scanning

The DefaultNancyBootstrapper auto registration takes all types from AppDomain.CurrentDomain.GetAssemblies. In some scenarios though this isn’t great, as it only picks up those assemblies that are already loaded. As the bootstrapping is usually done very early in the life of the application it may easily be that the bootstrapping omits many of the types. Any missed then need to be hooked up manually. I wanted to enhance this scanning to require less help.


The bootstrapping needs to be flexible enough to allow the developer control over which assemblies/types are not scanned, and to pass in extra assemblies for scanning which aren’t available for pickup automatically.


The bootstrapping should be configurable across various layers in a more complex system (so maybe a solution wide base bootstrapper, and then specific overrides for MVC/WebApi/Service projects).

After a few iterations I ended up with a nice lightweight solution, which had the configurability I was looking for.

You can see the whole project here, or jump straight to the bootstrapper class here.

SignalR: The ConnectionId is in the incorrect format – an alternative cause.

Recently, on an application using SignalR, we found that we were getting many System.InvalidOperationException: The ConnectionId is in the incorrect format exceptions (sometimes 10 per second) from the SignalR hubs in the site.

While there is plenty of discussion on the causes of this error in SignalR documentation and on Q&A sites, they mostly discuss problems with changing levels of authentication (SignalR defines a new connection when the auth level, or authorized user, changes). In this case though this wasn’t relevant. The volume implied that this was unlikely to be the cause, and in anycase, the site was already written to cope with these changes on login.

The cause turned out to be search engine crawler services. Continue reading SignalR: The ConnectionId is in the incorrect format – an alternative cause.

ASP.Net Webforms – Dynamic UpdatePanels and UserControls issue

Have come across an interesting issues in ASP.Net WebForms when migrating a project from 3.5 up to 4.5.

The site in question is extremely dynamic, the page is built up based on configuration in a CMS fashion.

However in 4.5 we have a problem – when more content is added into the page via a button click, not all the markup for the content appears.

Continue reading ASP.Net Webforms – Dynamic UpdatePanels and UserControls issue

Techniques for cleaner dynamic SQL generation

Very often when working in databases we have to resort to dynamic SQL generation to solve a problem. For example, common instances of this would be when performing an action across a number of different tables, or performing a PIVOT on a data set where the set of pivot results is not pre-determined. This latter example is one which I’ll take through this walk through.

The scenario is that we have a table of Person data and a table of Payslip data, and the requirement is to return each Person with the salaries listed out year on year. Its a simple example, but not unlike a real-world problem.

Continue reading Techniques for cleaner dynamic SQL generation

AutoMapper and EntityFramework Proxies – a workaround

This is a quick workaround for an issue I came across when working with AutoMapper on EF. Its one of those blog posts that’s as much a reminder for the writer as anything else.

I was trying to repopulate an entity instance from a corresponding model instance using a line similar to the following:

Mapper.Map<MyModel,MyEntity>(model, ent);

At this line I got an AutoMapper.AutoMapperMappingException accompanied by the following message:

Missing type map configuration or unsupported mapping. Mapping types: MyModel-> MyEntity_238F6DF9C0DAD0768B6BF2E9… MyProject.MyModel-> System.Data.Entity.DynamicProxies.MyEntity_238F6DF9C0DAD0768B6BF2E9…

Take as read that I certainly did have a Mapper.Create<MyModel,MyEntity>() type line in place.

Continue reading AutoMapper and EntityFramework Proxies – a workaround

DropDownList Helper For Enums

Its useful to be able to have a helper that converts a Enum typed property from an MVC Model directly into a drop down list without any messing about creating lists of possible values etc.

I found this answer on StackOverflow which has example code for just such a helper: EnumDropDownListFor. However, like a few who have tried it I found some issues around getting it to work to pre-select the value held in the Model’s property.

Continue reading DropDownList Helper For Enums

EditorFor and Interfaces Pt2 – Binding

This is a two part piece on working with Interfaces in MVC via the Html.EditorFor helper.

In the first part – “Display” just covers one of those things I tried on the off chance, and was rather surprised that it worked right out of the box.

In this second part I’ll have a look at the next step of the process – binding these interfaces back to their models.

For reference, I’m working with MVC4, in VS 2012 For Web. I think this will also work in MVC3 at least.


When model data is posted back from the client, an instance of the model class is automatically created for it and passed to the handling action. The process of converting the data into a model instance is called binding, and, normally, this is handled for us automatically.

If, as in Part 1, we’re using an interface as a model, and then allowing EditorFor to automatically render the correct controls this processes stops working, as the automatic binding isn’t able to resolve our interface into a concrete class to instantiate and fill.

Instead we have to implement a custom binding. In the case of interfaces we can make this fairly simple with Generic BaseInterfaceBinder that will work for all interfaces we might want to work with.

Continue reading EditorFor and Interfaces Pt2 – Binding

EditorFor and Interfaces Pt1 – Display

This is a two part piece on working with Interfaces in MVC via the Html.EditorFor helper.

The first part – “Display” just covers one of those things I tried on the off chance, and was rather surprised that it worked right out of the box.

In the second part I’ll have a look at the next step of the process – binding these interfaces back to their models.

For reference, I’m working with MVC4, in VS 2012 For Web. I think this will also work in MVC3 at least.


For a slightly messy user interface I’m working on, I wanted to be able to have a Model that holds a list of classes that implement an interface.

There is a possibility that all the classes might not be the same, and I was concerned that I was going to end up with a messy switch statement in my View that called the right Partial depending on which class I found in the list, and that this switch might need to be maintained on an on-going basis.

Continue reading EditorFor and Interfaces Pt1 – Display