Search code examples
c#azureazure-diagnostics

Problems in upgrading to Window Azure 2.5


I tried to upgrade to Window Azure SDK 2.5 from 1.8 by creating a new Azure Cloud Service project. But got error when deploying to azure cloud:

Your role instances have recycled a number of times during an update or upgrade operation. This indicates that the new version of your service or the configuration settings you provided when configuring the service prevent the role instances from running. Verify your code does not throw unhandled exceptions and that your configuration settings are correct and then start another update or upgrade operation.

The old azure project in Azure SDK 1.8 worked fine. When debugging locally, I got crash in WebRole.cs (created in SDK 1.8). The error message is:

An exception of type 'System.NullReferenceException' occurred in OTP.Ring.Web.dll but was not handled in user code

It happen at:

diagnosticsConfig.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(60);

So I think WebRole.cs should be changed, probably involving WindowsAzure.Diagnostics. I need help on how to change WebRole.cs. Its code is as follow:

   public class WebRole : RoleEntryPoint
    {
        public override bool OnStart()
        {
            var diagnosticsConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();

            diagnosticsConfig.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(60);
            if (ExtensionMethods.GetConfigurationSetting("loggingLevel") == Common.Logger.LogType.ERROR.ToString())
            {
                diagnosticsConfig.Logs.ScheduledTransferLogLevelFilter = LogLevel.Error;
            }
            else if (ExtensionMethods.GetConfigurationSetting("loggingLevel") == Common.Logger.LogType.DIAGNOSTIC.ToString())
            {
                 diagnosticsConfig.Logs.ScheduledTransferLogLevelFilter = LogLevel.Warning;
            }
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagnosticsConfig);

            Logger.LogDiagnostic("Starting WebRole");

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
            RoleEnvironment.Changing += RoleEnvironmentChanging;

            return base.OnStart();
        }

        private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
        {
            // If a configuration setting is changing
            if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
            {
                // Set e.Cancel to true to restart this role instance
                e.Cancel = true;
            }
        }
    }

Solution

  • Please note that code based diagnostics configuration is no longer supported starting SDK 2.5. This was mentioned in SDK 2.5 release notes: https://msdn.microsoft.com/en-us/library/azure/dn873976.aspx (Please see Breaking Changes section). I believe you're getting the error because of this.

    Another thing I would recommend is to upgrade your solution to SDK 2.6 instead of 2.5. SDK 2.6 was released late last month and has addressed some of the issues that were discovered in 2.5.