File tree Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ internal struct DYNAMIC_TIME_ZONE_INFORMATION
6161
6262 internal const uint TIME_ZONE_ID_INVALID = 0xffffffff ;
6363 internal const uint ERROR_NO_MORE_ITEMS = 259 ;
64+ internal const uint ERROR_SUCCESS = 0 ;
6465
6566 [ DllImport ( "api-ms-win-core-timezone-l1-1-0.dll" ) ]
6667 internal extern static uint EnumDynamicTimeZoneInformation ( uint dwIndex , out DYNAMIC_TIME_ZONE_INFORMATION lpTimeZoneInformation ) ;
@@ -349,7 +350,7 @@ internal static List<TimeZoneInfo> GetSystemTimeZonesWinRTFallback ()
349350 try {
350351 uint index = 0 ;
351352 DYNAMIC_TIME_ZONE_INFORMATION dtzi ;
352- while ( EnumDynamicTimeZoneInformation ( index ++ , out dtzi ) != ERROR_NO_MORE_ITEMS ) {
353+ while ( EnumDynamicTimeZoneInformation ( index ++ , out dtzi ) == ERROR_SUCCESS ) {
353354 var timeZoneInfo = TryCreateTimeZone ( dtzi ) ;
354355 if ( timeZoneInfo != null )
355356 result . Add ( timeZoneInfo ) ;
@@ -358,8 +359,6 @@ internal static List<TimeZoneInfo> GetSystemTimeZonesWinRTFallback ()
358359 // EnumDynamicTimeZoneInformation() might not be available.
359360 }
360361
361- if ( result . Count == 0 )
362- result . Add ( Local ) ;
363362 return result ;
364363 }
365364 }
Original file line number Diff line number Diff line change @@ -787,6 +787,10 @@ public static ReadOnlyCollection<TimeZoneInfo> GetSystemTimeZones ()
787787 if ( systemTimeZones == null ) {
788788 var tz = new List < TimeZoneInfo > ( ) ;
789789 GetSystemTimeZonesCore ( tz ) ;
790+ // Don't want to return an empty list if we can help it
791+ // but we don't want to stack overflow via a CreateLocal loop
792+ if ( tz . Count == 0 && local != null )
793+ tz . Add ( Local ) ;
790794 Interlocked . CompareExchange ( ref systemTimeZones , new ReadOnlyCollection < TimeZoneInfo > ( tz ) , null ) ;
791795 }
792796
You can’t perform that action at this time.
0 commit comments