Commit 96aca8ee authored by Marc Gravell's avatar Marc Gravell Committed by GitHub

Merge pull request #498 from wangzq/bug/Azure-RoleEnvironment-IsAvailable

Check Azure RoleEnvironment.IsAvailable before getting CurrentRoleIns…
parents 87de5fb2 e439f2cf
......@@ -125,7 +125,11 @@ internal static string TryGetAzureRoleInstanceIdNoThrow()
if (asm == null)
return null;
var currentRoleInstanceProp = asm.GetType("Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment").GetProperty("CurrentRoleInstance");
var type = asm.GetType("Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment");
// https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.isavailable.aspx if (!(bool)type.GetProperty("IsAvailable").GetValue(null, null)) return null;
var currentRoleInstanceProp = type.GetProperty("CurrentRoleInstance");
var currentRoleInstanceId = currentRoleInstanceProp.GetValue(null, null);
roleInstanceId = currentRoleInstanceId.GetType().GetProperty("Id").GetValue(currentRoleInstanceId, null).ToString();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment