From this blog post, it seems I should be able to store a DateTime
as a ApplicationData.LocalSettings
value, but I'm getting the exception below for this line.
ApplicationData.Current.LocalSettings.Values["LastTokenRefresh"] = DateTime.UtcNow;
https://blogs.windows.com/buildingapps/2016/05/10/getting-started-storing-app-data-locally/#bgpwEqDbEt0GClHB.97
Exception:
Data of this type is not supported.
Error trying to serialize the value to be written to the application data store
What am I missing?
I'm currently converting the DateTime
to string to make this work.
I think it's a link redirection issue of that Blog which causes your misunderstanding of supported data type DateTime
. You can refer to the official document: Types of app data, the DateTime
in this document will link you to DateTime structure:
JavaScript: This type appears as the Date object.
.NET: When programming with .NET, this type is hidden, and developers should use the System.DateTimeOffset structure.
C++: Similar to FILETIME but with important differences.
It means, the supported type for date here is System.DateTimeOffset Structure, not System.DateTime Structure. So, you can either modify your code like this:
ApplicationData.Current.LocalSettings.Values["LastTokenRefresh"] = DateTimeOffset.UtcNow;
Or you can keep using your ToString()
method to save it, but when you retrieve this string type value, you may need to rebuild the string for using it in your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With