Sparhawk
Sparhawk

Reputation: 1577

Azure RoleEntryPoint not called?

I've deployed my solution to an Azure CloudService using SDK version 2.6. The solution is running fine and now I want to configure some IIS settings from the RoleEntryPoint (like keeping the Threadpool always running).

Whatever I do, it seems that my RoleEntryPoint is never called. I am trying to trace information, I am throwing exceptions, I am even returning "false" in OnStart(). I deploy my package, the Cloudservice instances restart and everything is fine.

This is my simple class:

using System;
using System.Diagnostics;
using System.Linq;
using Elmah;
using Microsoft.Web.Administration;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.ServiceRuntime;
using Telerik.Sitefinity.Cloud.WindowsAzure;

namespace SitefinityWebApp
{
public class AzureWebRole : RoleEntryPoint
{

    public override void Run()
    {
        Trace.WriteLine("Entering Run method");
        Trace.TraceInformation("Run");

        base.Run();
    }
    public override bool OnStart()
    {
        return false;
        Trace.WriteLine("Entering OnStart method");
        Trace.TraceInformation("OnStart");

        throw new System.ApplicationException("you are going down!");

        return base.OnStart();
    }
}
}

This class is in my main WebRole-Assembly. After deploying I tried "Reimaging" and restarting the VM. Both should be unnecessary but I wanted to make sure that the role gets a chance to call the RoleEntryPoint.

Any idea why the code is not called? I understand that returning "false" from the OnStart should have the effect that the role doesn't start at all? Why does the role start?

Upvotes: 4

Views: 2670

Answers (1)

SliverNinja - MSFT
SliverNinja - MSFT

Reputation: 31641

Our RoleEntryPoint was also not starting for the Azure Cloud Service Web Role. To fix this issue - the following steps worked for us:

Fix RoleEntryPoint not getting called

  1. Remove All Project References in your Web Role to Azure, and remove the packages.config
  2. Remove the current Web Role from your Azure Project (ccproj)
  3. Re-add your Web Role to the Azure Project (this re-adds the dependencies)
  4. Observe the updated packages.config and Project References.
  5. In your Web Role, Ensure Microsoft.WindowsAzure.ServiceRuntime Project Reference has Copy Local = true

@mohamed-abed led us to this solution, we had a version mismatch between the Azure SDK and the unofficial nuget package for Azure Runtime.

The essential rule is that your CCPROJ ProductVersion should match the Assembly version referenced in your Web Role or the RoleEntryPoint will not be invoked.

Upvotes: 2

Related Questions