I blogged about VB.NET’s IIF-statements few years ago. As I mentioned back then, they are a handy way to shorten the code and to make it more readable but also a great way to introduce subtle bugs into our systems. Here’s the part 2 two that blog post, dealing with If statements and nullable variables.

Given the following VB.NET code:

        Dim amount = 100
        Dim newAmount As Integer? = If(amount = 100, Nothing, 50)

        Console.WriteLine("New value: {0}", newAmount)

With the first glance it’s quite obvious that the app will print “New value:  ” as we’re setting newAmount to nothing. But when run, here’s what we see:


Strange. NewAmount isn’t “nothing” as we thought, it’s actually 0. To correct the issue, we have to cast the “nothing” to nullable integer:

        Dim amount = 100
        Dim newAmount As Integer? = If(amount = 100, CType(Nothing, Integer?), 50)

        Console.WriteLine("New value: {0}", newAmount)

And this time we get the desired output:


Portable Class Libraries are a great way to share common code between different platforms. But here lies the danger: A portable class library project cannot change the underlying platform.

Here’s a simple explanation of what that means.

Example project

The example application is built for Windows Forms, Windows RT and Windows Phone. The authentication mechanism is identical in every app so that is placed in a Portable Class Library project:

    public class WebTool
        public async Task<string> GetAuthenticationKey()
            var cookieContainer = new CookieContainer();
            var client = new HttpClient(new HttpClientHandler() { CookieContainer = cookieContainer });

            // Authenticate with the service
            await client.GetStringAsync("http://cookietest.api.domain.com/cookie/get");

            // Return the received cookie as authentication key
            var cookieHeader = cookieContainer.GetCookieHeader(new Uri("http://cookietest.api.domain.com/"));

            return cookieHeader;

Using this library doesn’t get easier: Each platform can call it with identical code:

            var webTool = new WebTool();

            var result = await webTool.GetAuthenticationKey();

            if (string.IsNullOrWhiteSpace(result))
                this.Result.Text = "Didn't receive authentication key!";

                this.Result.Text = "Authentication key: " + result;

Few minutes and everything is done, so the testing phase begins.

First, Windows Forms:


Then Windows 8:


And last but not least, Windows Phone:


Uh oh.

Cookies and CookieContainer especially are different beasts in different platforms. Portable Class Library cannot hide that fact.

Have you encountered similar issues when dealing with Portable Class Library projects?


As the PC makers seem to have some problems getting the Haswell based ultrabooks to market, I decided to get MacBook Air 2013 (MBA 13 i5 model) and use it as my main development machine with the help of Boot Camp. UnfortunatelyI encountered a deal breaker:  I couldn’t turn on Hyper-V in Windows 8:

Hyper-V cannot be installed: Virtualization support is disabled in the firmware

Hyper-V is required when one wants to do Windows Phone 8 development, which I do quite much.

But fortunately, there’s a fix for this, though it has couple problems:

  1. It costs money
  2. The solution is just bizarre

In order to enable Hyper-V you have to follow these steps:

  1. Boot the computer into Mac OS X
  2. Purchase (or get the trial), download and install Parallel Desktop for Mac
  3. Reboot back to Windows 8

And that’s it, the Hyper-V is now available.


If you turn off the computer at some point, the Hyper-V gets disabled until you boot into Mac OS X and run the Parallel Desktop again. So it’s better just to put the MacBook to sleep.

Bizarre, isn’t it?

I suppose this is just a bug in the firmware as MBA 12 seems to support the Hyper-V just fine. But, until the bug is fixed, this works as a workaround. Thanks to TigerG for posting his findings at MacRUmors.


After my TechDays’ presentation I was asked why we prefer to use Azure Virtual Machines for our web site hosting instead of Azure Web Roles. Here’s a little more structured answer to that question.

Our requirements

Let’s start by going through our requirements for the web site hosting platform. The main things we hope to have are:

  • Ease of deployment
  • Support for running ASP.NET and Node.js sites
  • Support for custom certificates

The problem with Azure Web Sites

Even though the original question didn’t touch Azure Web Sites, I thought about covering that option too. The Azure Web Sites is a great platform but it has a one big glaring problem, making it unsuitable for the production usage: The lack of support for custom certificates.

Other than that, Azure Web Sites offer really fast and easy deployment options and also the Node.js is supported.

Almost there with Azure Web Roles

The Azure Web Roles provide the support for custom certificates and for Node.js, making it ready for production usage. But the platform lacks in the ease of deployment. By default, updating a site is slow and it’s hard to run multiple applications in the same Web Role. The last bit is especially true if one wants to run both Node.js and ASP.NET apps on the same role.

The Azure Web Role platform pushes the developer into the “one app, one service” direction. This causes problems when you have limited resources (money).

Flexibility with Azure Virtual Machines

If you want to combine the Azure Web Site''s’ ease of deployment with Azure Web Roles’ readiness for production usage, the Azure Virtual Machines offer a good solution. Even though it takes some time to set things up, there’s plenty of good documentation available. We’ve setup our web servers using the following tools:

  • DFSR to keep the web servers in sync
  • IIS configured to use “shared configuration” and “Centralized Certificate Store”.
  • Web Deploy enabled on one of the servers (provides the options to “Push” web sites from Visual Studio)
  • IISNode for running Node.js
  • FTP-deploy for static sites and Node.js apps
  • Load Balancing is handled by Azure’s built-in load balancer


Here’s our requirements and the hosting options collected into a single table.

Feature / PlatformAzure Web SitesAzure Web RolesAzure Virtual Machines
Ease of DeploymentXX
Custom certificatesXX

Other options:

Windows Azure Accelerator for Web Roles

Windows Azure Accelerator for Web Roles deals with the deployment problem of the platform. Unfortunately, the original project is now deprecated. Fortunately, robdmoore’s fork of the project is been actively developed.

The Azure Web Sites Private edition

The tools for running a private Azure Web Sites platform are available from the Web Platform Installer (Windows Azure / Service Management…). It seems that these tools support custom certificates. More info about this solution is available through the Microsoft.com/hosting.


I’ve been processing a lot of messages through Azure Service Bus lately. During that processing I encountered a situation where Azure Management Portal reported that there were over 97 thousand messages in the queue but still the worker weren’t receiving any messages.


Turns out the Management Portal also reports messages in the Dead Letter Queue. Some of the messages had failed the processing few times so they had been automatically moved to the Dead Letter Queue.

Here’s a code snippet for creating a QueueClient for the DLQ, from a previously created QueueClient:

var client = QueueClient.CreateFromConnectionString(conn, queue);

if (deadLetter)
var dfQueue = QueueClient.FormatDeadLetterPath(client.Path);
var dfClient = QueueClient.CreateFromConnectionString(conn, dfQueue);