ApplicationData.Current.LocalSettings and DateTimeOffset.MinValue

Hong 1,206 Reputation points
2019-12-22T00:30:03.113+00:00
  ApplicationDataContainer localSettings = ApplicationData.Current?.LocalSettings;
  localSettings.Values["foo"] = DateTimeOffset.MinValue;
  DateTimeOffset dto = (DateTimeOffset)localSettings.Values["foo"];

The last line of the above code throws the following exception

"Specified argument was out of the range of valid values."

   at System.DateTime.ToLocalTime(Boolean throwOnOverflow)
   at System.DateTimeOffset.ToLocalTime(Boolean throwOnOverflow)
   at System.StubHelpers.DateTimeOffsetMarshaler.ConvertToManaged(DateTimeOffset& managedLocalDTO, DateTimeNative& nativeTicks)
   at System.Runtime.InteropServices.WindowsRuntime.IReference`1.get_Value()
   at System.Runtime.InteropServices.WindowsRuntime.CLRIReferenceImpl`1.UnboxHelper(Object wrapper)
   at System.StubHelpers.InterfaceMarshaler.ConvertToManaged(IntPtr pUnk, IntPtr itfMT, IntPtr classMT, Int32 flags)
   at System.Runtime.InteropServices.WindowsRuntime.IMap`2.Lookup(K key)
   at System.Runtime.InteropServices.WindowsRuntime.MapToDictionaryAdapter.Lookup[K,V](IMap`2 _this, K key)

What is the range of valid values?

Universal Windows Platform (UWP)
{count} votes