-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Description
This (bad) code here behaves differently for Windows and macOS:
using System;
using System.Globalization;
class Program
{
private static CultureInfo _parsingCulture;
static void Main(string[] args)
{
_parsingCulture = (CultureInfo)CultureInfo.InvariantCulture.Clone();
_parsingCulture.DateTimeFormat.Calendar = new AsnUTCTimeCalendar();
}
private class AsnUTCTimeCalendar : GregorianCalendar
{
public override int ToFourDigitYear(int year) => (year < 50 ? 2000 : 1900) + year;
}
}On Windows, this throws an exception:
System.InvalidOperationException: Cannot set sub-classed Program+UTCTimeCalendar object to System.Globalization.DateTimeFormatInfo object.
On macOS, an exception is not thrown and it "works".
I understand why the Windows version is throwing, but I was surprised that it did not on macOS. I think the correct behavior is that all platforms should throw the exception.
Runtime Environment:
OS Name: Windows
OS Version: 10.0.14393
OS Platform: Windows
RID: win10-x64