-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preferences DateTime Storage Issues #25930
Comments
I thought I had provided steps, do you need something else? |
I see that we store a long for Edit DateTimeOffset is net9, but I see the code in net8 always was a DateTime to long: https://github.com/dotnet/maui/blob/release/8.0.1xx-sr10/src/Essentials/src/Preferences/Preferences.android.cs#L84-L86 Maybe a repro sample will help. |
Well, I don't use that type intentionally @mattleibow , but who knows? You'll note that the repro steps I provided call |
Here's a project https://github.com/david-maw/Community-Preferences.git. It's basically my sample code from above wrapped in a UI. Build and run it on Windows (it defaults to .NET 8) and click the button and I hope you'll see what i did: Repeat the process under .NET 9 (there's a branch for convenience) and instead of the textual date you'll see 638672549500000000. So .NET 9 appears to behave as you describe, storing a |
Thanks for the sample I'll check it out. |
Wow, ok. I will check it out. Very strange. |
It is strange, I couldn't find a Preference.Set call that took a DateTimeOffset parameter so it's probably not that. I added some workaround code just in case anyone else gets bitten by this. With the workaround in place, it's no longer a significant issue for me. |
I think I see what is happening here... This has to do with the different implementations of the preferences API on Windows depending on packaged or unpackaged.
The implementation differs:
The real change comes in at this PR: https://github.com/dotnet/maui/pull/22815/files#diff-6ed591e38dc7754551705bf5bb96f992115c384d19166e8dcda76267e177fb0cR196-R197 In .NET 8 everything was a "ToString" system for unpackaged. In .NET 9 there is now a ToBinary. I think this may have been too aggressive a change (even though it is correct) and should have had a fallback. I will do a PR for that now. |
I'm not going to pretend I understand all of that explanation, but I certainly understand the outcome, so thanks. |
Description
On .NET 8 a Preferences.Set of a DateTime type would store a string but in .NET 9 it seems to store a long. This has two issues:
Message=java.lang.Long cannot be cast to java.lang.String
The .NET 9 versions of Preferences.Get and Preferences.Set are compatible with each other as are the .NET 8 versions, it's writing a value with one and reading it with the other that's a problem. The new scheme seems better, but it needs to migrate cleanly.
Steps to Reproduce
Create a default MAU App and insert
using CommunityToolkit.Maui;
and this code:Run this on Windows (it will fail on Android) and examine the string, on .NET 9 it will contain "638672549500000000" whereas on .NET 8 it will be "11/15/2024 08:09:10".
Link to public reproduction project repository
No response
Version with bug
9.0.0 GA
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
8.0.100 SR10
Affected platforms
Android, Windows, I was not able test on other platforms
Affected platform versions
No response
Did you find any workaround?
Explicitly converting a string works on Windows but because long-to-string faults on Android it's trickier there.
Relevant log output
The text was updated successfully, but these errors were encountered: