To install Windows 7 on a virtual disk, follow these instructions.

  • Boot from the Windows 7 installation disc
  • Press SHIFT+F10 to open the command prompt
  • Start diskpart.exe
  • If you already haven’t already created a vdisk that you would like to install Win7 on, create one (see previous post)
  • Attach the virtual disk

    > select vdisk file="C:\path\to\vhd"
    > attach vdisk
    > exit

  • Continue with the installation by selecting “Custom Install”
  • Select the virtual disk (if you have formatted and named your disk, you will see that name now, otherwise you will have to consider the disk size)
  • Install Windows 7

The installer will create a boot menu entry for your new Windows installation and your existing non-virtual installation. Unfortunately, they are (by default) both called “Windows 7”. Very helpful… The virtual installation will be the first entry in your boot menu and started by default. Once your installation is complete, you can fix this issue with the “bcdedit.exe” command line tool.

Open a command prompt as administrator and follow these steps:

> bcdedit.exe

This will give you a list of all boot manager entries. Find the one that refers to your VHD file and copy it’s ID – {current} if you are currently running your virtual installation and usually {default} if you’re running the physical installation.

> bcdedit.exe /set description "New boot menu entry"

You can also create copies of your bood menu entries and adjust them to, let’s say, point to a different VHD file.

There is this fancy new feature in Windows 7 called “Boot from VHD”. It essentially allows you to boot your machine from a virtual disk without having to virtualize the rest of your hardware. This can be quite helpful if you want to experiment with your Win7 without reinstalling all the time because you screwed up.

First I’ll explain how you can create and manage virtual disks. In the second part I will discuss how to install a second Win7 on the created virtual disk and how to set up the bootloader correctly.
Continue reading Win7 Boot from VHD – Part I

Today I ran into this problem for the second (and hopefully last) time. Let’s take a look at the words “sorted” and “list”. “sorted” suggests that the items of the list will somehow be sorted. So far, so good. “list” would suggest that you can put any item in the list. Specifically, it isn’t called “SortedSet”, so you could expect that you in fact can add the same item twice with the same key.

Well… that’s where you’d be wrong. The documentation says that the sorted list throws an ArgumentException if “An element with the same key already exists in the SortedList”. Unfortunately I don’t go around looking through the documentation to search for stuff like that. And in fact: you shouldn’t have to. A list is a list and not a set. And if you decide to implement a sorted list with a dictionary as the backing store, then you are – quite frankly – an idiot.

If you would like to save yourself a lot of grief, just don’t use the sorted list. Use a regular List and the Sort method. But be aware, that the Sort method uses the quicksort algorithm which is unstable (elements that are “equal” don’t keep their relative positions to one another).

On Friday I tried to update one of the legacy DataSets of the application I’m working on. When I double-clicked the data set schema, VS just opened the XML view to edit the schema. Quite useless. So I right-clicked the item and selected “View Designer” which then brought up a new window that contained all the inner text of the XML document as one large blob. More than just useless…
Today I started looking for a solution or possible cause for the problem. It would seem that the data set designer was not loaded on VS startup. The solution then was quite simple: Open a command line and start

devenv /resetskippkgs

This tells VS to reset its list of skipped packages and load everything. Now I can use the designer again.

When using a AutoCompleteExtender from the AjaxToolkit, Firefox may show it’s own AutoComplete List over the one you want. To disable that, you need to disable autocomplete on the Field or the entire Form.

To do that, just add an autocomplete="off" to the Textbox in the Markup Code or add the Attribute on Runtime like this:

Textbox1.Attributes.Add("autocomplete", "off");

Today, I tried to add the AjaxControlToolkit Controls to my Toolbox in Visual Studio 2008. But when I selected “Choose Items…” in the Toolbox, Visual Studio just crashed without any Errors.

That could happen because of some defect or deinstalled Toolbox Items.

Here’s how to fix that:

  1. Search the Binary devenv.exe
  2. Start it with the command line Parameter /safemode
  3. Use Choosse Items... in the Toolbox
  4. Click thru all the Tabs
  5. Close Visual Studio
  6. Open Visual Studio normally and it should work again

Some old Visual Studio Solutions may come up with this little annoying error on startup.

Here’s how to fix it:

Open the <yourproject>.vspscc File for the defect Project.
It will look like:

""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "COMPULSORY"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = "http://localhost/<yourproject>.vbproj"
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}

Change the Value from ENLISTMENT_CHOICE from COMPULSORY to NEVER and remove the Value from ORIGINAL_PROJECT_FILE_PATH.

The File now looks something like:

""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}

Save the File.

Now remove the defect Project from your Solution and re-add it. This basically removes the Line SccProjectEnlistmentChoice<xx> = <yy> from your Solution File and possibly some other legacy Lines.

Now you’re done! Finally got rid of that annoying Message!

Sometimes you want to catch and specially handle an SQL-Timeout.
To do this, just put a try-catch around your SQL-Call and catch the SqlException. Now check the Property Number if it is -2 (which stands for Timeout). That’s it.

Here’s a little Code Example how that could look like:

try
{
	RunSomeSqlQuery();
}
catch (SqlException ex)
{
	// Check if it's a TimeoutException
	if (ex.Number == -2)
	{
		// It is...
		// Do whatever you need
	}
	else
	{
		// Other Type of Exception, re-throw it or whatever
		throw;
	}
}

If you want to simulate a Timeout in your SQL-Statement, just use the WAITFOR DELAY SQL-Statement to block for some Time and therefore results in a Timeout.

Here’s an example to wait for 1 Minute:

WAITFOR DELAY '00:01:00'

I like XML. I like it a lot. For most smaller applications a database – even SQLite and the likes – is complete overkill. Still, you have to save your application data somewhere. Enter XML.

I also like to access my application data in a typesafe manner and I don’t like to reinvent the wheel (or in this case, the XML serialization). Enter System.Xml.Serialization. Continue reading System.Xml.Serialization