Microsoft.WindowsAzure.* assemblies not in GAC on Azure sites

by ingvar 16. april 2011 16:34

I discovered something ord with Azure deployments. 99% of developers and Azure deployments will probably never encounter. To put it short if discovered that if the website you deploy to Azure does not have a reference to the assembly Microsoft.WindowsAzure.StorageClient.dll, the assembly can not be used by the website at all. In other words, this assembly is not in the GAC. Many will probably find this scenario strange. But I encountered this issue when I was working with the CMS Composite C1. C1 is deployed to Azure buy the WebRole.OnStart method that downloads a zip file and unzipping it to the website. Why? Well, there are many reasons, but one of them is that this allows developers deploying existing C1 sites to Azure with the same Azure deployment package (no need to rebuild the package). They just zips the site and points to it from the ServiceConfiguration.cscfg file. 

I wanted to share this, so I have found an easy way to reproduce it. Here is the steps to reproduce it (A zipped version can be downloaded Here):

  1. Create new windows azure project.
  2. Add a ASP.NET WebRole (Clean the site so only WebRole.cs and web.config are left).
  3. Add Empty ASP.NET website.
  4. Add the physicalDirectory=”../Website” to the Site element in the ServiceDefinition.csdef file.
  5. Add a Default.aspx to the website (Not the WebRole) with the code below.
  6. Deploy to Azure.
  7. Note that the CloudBlob type is not found!
  8. Add a Default.aspx with the same code to the WebRole project.
  9. Change the physicalDirectory to “../WebRole” in the ServiceDefinition.csdef file.
  10. Deploy to Azure.
  11. Now the types can be found! (WebRole having a reference to the needed assembly)

Here is ths code I added to the Default.aspx.cs files:

protected void Page_Load(object sender, EventArgs e)
{
    Type cloudBlobType = Type.GetType("Microsoft.WindowsAzure.StorageClient.CloudBlob, "
      "Microsoft.WindowsAzure.StorageClient");
    if (cloudBlobType != null)
    {
        PlaceHolder.Controls.Add(new LiteralControl("Type found! <br />"));
    }
    else
    {
        PlaceHolder.Controls.Add(new LiteralControl("Type NOT found! <br />"));
    }
}

I used Type.GetType here only to do the reproduction. This could also happen, as it did with C1, if an assembly is added to the website from the WebRole.OnStart, that have a reference to Microsoft.WindowsAzure.StorageClient.dll and used in the code. In this case the site is totaly dead.  

The fix is easy, just add needed references to the website. The reason that the WebRole in this reproduction works is that it has a reference to the needed assembly and this results in that the assembly is in the bin folder. 



Tags:

.NET | Azure | C#

About the author

Martin Ingvar Kofoed Jensen

Architect and Senior Developer at Composite on the open source project Composite C1 - C#/4.0, LINQ, Azure, Parallel and much more!

Follow me on Twitter

Read more about me here.

Read press and buzz about my work and me here.

Stack Overflow

Month List