Commit e439f2cf authored by Walter Wang's avatar Walter Wang

Check Azure RoleEnvironment.IsAvailable before getting CurrentRoleInstance to...

Check Azure RoleEnvironment.IsAvailable before getting CurrentRoleInstance to avoid unnecessary exception.
parent 32807af6
......@@ -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