Azure Web Role stuck initializing-Collection of common programming errors

edit: I figured it out. Well almost 🙂 I fixed this issue, but I found another one. Documenting the solution here.

I have an MVC web role I am trying to deploy to Azure. It keeps bouncing from Starting > Initializing. I have done my research, and found two main causes for this.

  1. One of the assemblies I am using does not have Copy Local = True set
  2. The diagnostics connection string is wrong.

I Have triple checked my diagnostics connection and it is fine. I can use the exact same connection string in a Worker Role and it starts just fine So I assume the problem is related to #1 above.

This was a standard MVC project I added an azure deployment project to, so my guess is I am missing something an “Azure web role project” would automatically do for me. I already selected the “Add deployable assemblies” option from the projects context menu so the MVC bits should be set up, right?

Here is a list of my references, the items highlighted have Copy Local = true. Am I missing one? What else do I need to do to get this to deploy? Are there any diagnostics tools I can use to help me figure it out?

update:
I love when I find more information 🙂

So I was finally able to catch it in a state when I can remote into the server. I opened IIS and saw everything was there that should be. I tried to hit the site locally, but I get this error. The assembly IS included in my deploy, so it doesn’t make sense that it can’t find it. It seems like it is trying to load a different version than what was packaged.

Could not load file or assembly ‘System.Web.WebPages’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

So there is (at least one of) my error…..but why? The site runs fine in IIS express, and it runs fine in development fabric. I feel like a noob here. What did I do wrong?

  1. I had a reference to V2 of System.WebPages, but bin_dependencies had V1 in there. I Don’t know how this happened, but making sure everything was on the right version worked.

  2. I would like to know which MVC version you’re using. If you use MVC 3 or 4, please redirect the CLR runtime to the new versions of the assemblies. For example, for MVC 3:

      
        
          
            
            
          
        
      
    

    If you create a new MVC web role, this will be automatically configured. If you migrate an existing MVC application to Windows Azure, it is needed to configure it manually.

    Best Regards,

    Ming Xu.

  3. You are missing some directly or indirectly referenced assemblies which are not packaged because they reside in your global assembly cache and are therefore assumed to be provided. Have a look at this answer and comments which should document the same issue.

  4. When you use ASP.NET MVC (3), you have to install it on the Azure. The easiest way to deploy is to use the neat feature “Add Deployable Dependencies”:

    You will find this option when you right click on the Web Application project (the Web Role itself, not the cloud project). Then just select ASP.NET MVC:

    This process will create a folder in your web app *_bin_deployableAssemblies*. And the framework will know what to do with it.

    Note

    The “Add Deployable Dependencies” is part of Visual Studio 2010 SP1. So if you haven’t already upgraded to SP1, I highly encourage you to do so 😉

  5. Not sure if this is the issue you’re running into, but… If session state is enabled, the default provider in web.config is SQL Express (based on the August 2011 update, where role templates now use all the universal providers). Since SQL Express isn’t installed on Windows Azure, this leads to web role startup trouble. You’d need to change the provider to SQL Azure or Cache. Nate Totten’s blog post about the Universal Provider update sheds more light on this.

    I answered a similar question here as well…