diff --git a/mcs/class/corlib/System/TimeZoneInfo.WinRT.cs b/mcs/class/corlib/System/TimeZoneInfo.WinRT.cs index bc9a31233723..f4a7ca7bbb46 100755 --- a/mcs/class/corlib/System/TimeZoneInfo.WinRT.cs +++ b/mcs/class/corlib/System/TimeZoneInfo.WinRT.cs @@ -61,6 +61,7 @@ internal struct DYNAMIC_TIME_ZONE_INFORMATION internal const uint TIME_ZONE_ID_INVALID = 0xffffffff; internal const uint ERROR_NO_MORE_ITEMS = 259; + internal const uint ERROR_SUCCESS = 0; [DllImport ("api-ms-win-core-timezone-l1-1-0.dll")] internal extern static uint EnumDynamicTimeZoneInformation (uint dwIndex, out DYNAMIC_TIME_ZONE_INFORMATION lpTimeZoneInformation); @@ -349,7 +350,7 @@ internal static List GetSystemTimeZonesWinRTFallback () try { uint index = 0; DYNAMIC_TIME_ZONE_INFORMATION dtzi; - while (EnumDynamicTimeZoneInformation (index++, out dtzi) != ERROR_NO_MORE_ITEMS) { + while (EnumDynamicTimeZoneInformation (index++, out dtzi) == ERROR_SUCCESS) { var timeZoneInfo = TryCreateTimeZone (dtzi); if (timeZoneInfo != null) result.Add (timeZoneInfo); @@ -358,8 +359,6 @@ internal static List GetSystemTimeZonesWinRTFallback () // EnumDynamicTimeZoneInformation() might not be available. } - if (result.Count == 0) - result.Add (Local); return result; } } diff --git a/mcs/class/corlib/System/TimeZoneInfo.cs b/mcs/class/corlib/System/TimeZoneInfo.cs index 7afdbd857de2..b84efd87afad 100644 --- a/mcs/class/corlib/System/TimeZoneInfo.cs +++ b/mcs/class/corlib/System/TimeZoneInfo.cs @@ -787,6 +787,10 @@ public static ReadOnlyCollection GetSystemTimeZones () if (systemTimeZones == null) { var tz = new List (); GetSystemTimeZonesCore (tz); + // Don't want to return an empty list if we can help it + // but we don't want to stack overflow via a CreateLocal loop + if (tz.Count == 0 && local != null) + tz.Add(Local); Interlocked.CompareExchange (ref systemTimeZones, new ReadOnlyCollection (tz), null); }