Ich stoße auf ein Problem, bei dem meine Bereitstellung eine Schleife durchläuft. Von Visual Studio.Eine Ausnahme in der onStart-Methode einer Azure-Worker-Rolle abfangen?
„Role-Instanzen für eine gewisse Zeit bei einer Aktualisierung recycelt oder Betrieb aktualisieren Dies zeigt, dass die neue Version Ihres Dienstes oder die Konfigurationseinstellungen, die Sie bei der Dienstrolle Konfiguration Instanzen nicht ausgeführt werden. Der wahrscheinlichste Grund dafür ist, dass Ihr Code eine nicht behandelte Ausnahme auslöst.Bitte denken Sie darüber nach, Ihren Dienst zu reparieren oder die Konfigurationseinstellungen zu ändern, damit Rolleninstanzen keine unbehandelten Ausnahmen auslösen. Starten Sie dann einen weiteren Aktualisierungs- oder Aktualisierungsvorgang Windows Azure versucht weiterhin, Ihren Dienst auf die neue Version oder Konfiguration zu aktualisieren. "
Meine Frage: Was ist der beste Weg, um die Ausnahme zu fangen? Ich bin ein bisschen neu in C#. Eine verkürzte Version meiner onStart falls es hilft:
public override void Run()
{
// This is a sample worker implementation. Replace with your logic.
Trace.WriteLine("WorkerRole1 entry point called", "Information");
while (true)
{
Thread.Sleep(10000);
Trace.WriteLine("Working", "Information");
}
}
public override bool OnStart()
{
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 12;
// Retrieve storage account from Connection String
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create blob client
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// retrieve reference to container (blob resides within container)
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
// create container if it doesn't already exist
container.CreateIfNotExist();
// make container public *temp*
container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
// Retrieve references to required blobs
CloudBlob batch = container.GetBlobReference("batch.bat");
// Download batch file
using (var fileStream = System.IO.File.OpenWrite(@"C:\batch.bat"))
{
zip.DownloadToStream(fileStream);
}
// run batch file
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "C:\\batch.bat";
proc.StartInfo.RedirectStandardError = false;
proc.StartInfo.RedirectStandardOutput = false;
proc.StartInfo.UseShellExecute = false;
proc.Start();
proc.WaitForExit();
return base.OnStart();
}
}
}
Auch im Falle es, hier ist der Stack-Trace von RDP hilft:
Stack:
at System.IO.__Error.WinIOError(Int32, System.String)
at System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean)
at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, Int32, System.IO.FileOptions, System.String, Boolean)
at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare)
at System.IO.File.OpenWrite(System.String)
at WorkerRole1.WorkerRole.OnStart()
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleType)
at Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.<InitializeRole>b__0()
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()
Keine exakte Antwort auf Ihre Frage, aber Ihr Code versucht auf c zuzugreifen: Sie müssen diesen Zugriff durch den lokalen Speicher ersetzen: [link] (http://msdn.microsoft.com/en-us/library/ windowsazure/ee758708.aspx). Ein Beispiel: [link] (http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.localresource.aspx) – RichBower
Danke Rich! Das hat das Problem gelöst :) – RobVious