我尝试通过创建新的Azure Cloud Service项目从1.8升级到Window Azure SDK 2.5。但是在部署到azure云时遇到错误:
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.
Azure SDK 1.8中的旧azure项目运行良好。在本地调试时,我在WebRole.cs中崩溃了(在SDK 1.8中创建)。错误消息是:
An exception of type 'System.NullReferenceException' occurred in OTP.Ring.Web.dll but was not handled in user code
它发生在:
diagnosticsConfig.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(60);
所以我认为应该更改WebRole.cs,可能涉及WindowsAzure.Diagnostics。我需要有关如何更改WebRole.cs的帮助。其代码如下:
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;
}
}
}
答案 0 :(得分:1)
请注意,启动SDK 2.5 不再支持基于代码的诊断配置。 SDK 2.5发行说明中提到了这一点:https://msdn.microsoft.com/en-us/library/azure/dn873976.aspx(请参阅Breaking Changes
部分)。我相信你因此而得到错误。
我建议的另一件事是将您的解决方案升级到SDK 2.6而不是2.5。 SDK 2.6于上个月底发布,并解决了2.5中发现的一些问题。