zipswich avatar image
0 Votes"
zipswich asked FayWang-MSFT edited

ApplicationData.Current.LocalSettings and DateTimeOffset.MinValue

   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?

· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

When I tested the above code, it worked well. What's the value of your DateTimeOffset.MinValue? If you create a blank project to use the three lines of code, will the same issue occur? And what is the version number of your system and visual studio?

0 Votes 0 ·

Thank you for looking into this.
DateTimeOffset.MinValue = {0001-01-01 12:00:00 AM +00:00}

alt text

From a blank project:
alt text

alt text

Microsoft Visual Studio Enterprise 2019
Version 16.4.1
Microsoft .NET Framework
Version 4.8.03752

Installed Version: Enterprise

Architecture Diagrams and Analysis Tools 00433-90000-00004-AA783
Microsoft Architecture Diagrams and Analysis Tools

0 Votes 0 ·

When I used the same version to create a blank app and tested the three lines of code, it worked well. So can you provide a simple sample that can be reproduced for us to test? And can you show the detailed repro steps?

0 Votes 0 ·

Hi, is there any update? Do you solve issue? If not, can you provide a simple sample?

0 Votes 0 ·
Show more comments

0 Answers