Thursday 21 January 2010

Sometimes It Just Works

Some things in life that just do what they say they will do and when this happens you get blown away. 

VMware Workstation says it lets you use Visual Studio to debug an application that is running on a virtual machine.  I used this recently and was blown away by how easy it was to set up and by how amazingly useful it was.

The story is that I released a new build for informal testing, but it could not be installed.  I installed it onto a clean XP VM (yeah, I should have done that already…) and got the error myself.  However, there was no error information coming back from the application as the failure was happening before the logging layer was instantiated.

I was stuck.  I could reproduce, but had no other information to help.  Then I remembered that VMware Workstation had the facility to debug apps running on VMs.  So, I followed the instructions (yes, I was desperate enough to read the VMware help file!!) and set up a VM for remote debugging.  This was pretty swift to achieve and I then started a debugging session on the VM from Visual Studio. 

Almost immediately I could see what was happening: it was my bad – I’d just forgotten to include a third-party assembly with the build.  My dev box was happily loading it from the GAC and so I couldn’t see I’d missed anything.

VMware Workstation just did what it said it would do.  in doing so, it got me out of a sticky situation.  Also, it says it has the ability to record and replay a debugging session…maybe next time, eh?

In the meantime, and whilst loving the things that go right, here’s a shot of the error from VS debugging on the VM:

image

Thursday 7 January 2010

Friendly OS Name from WMI

When you want to find out what operating system your application is running on, System.Environment.OSVersion is not very readable.  You can get a nice friendly name using WMI like this:

  1: private static string GetOSName()
  2: {
  3:    const string query = "SELECT * FROM Win32_OperatingSystem";
  4:    var searcher = new ManagementObjectSearcher(query);
  5:    var results = from x in searcher.Get().OfType<ManagementObject>()
  6:            select x.GetPropertyValue("Caption");
  7:    return results.Any() ? results.First().ToString() : "Unknown";
  8: }


This will give you something like "Microsoft® Windows Server® 2008 Enterprise ".