Hello,
Could this be a recent Maui bug to be rectified soon, or could someone clarify if there are things to watch out for Microsoft.Maui.Storage.Preferences such as what impacts unintentional clearing of Preference keys and values?
Yes, I tested it in Maui version 6.0.419, I can get the value correctly in Android, windows and iOS.
But when I upgraded Maui version to 6.0.486, I got the same issue. Please report this issue on MAUI GitHub page.
I found a workaround to fix this issue, you can judge the value Preferences.Get(nameof(DatabaseName), $"{AppInfo.Name}.db")
, if the value is Null or whitespace, we can set a value like following code.
public static string DatabaseName
{
get {
if(string.IsNullOrWhiteSpace( Preferences.Get(nameof(DatabaseName), $"{AppInfo.Name}.db")))
{
Preferences.Set(nameof(DatabaseName), $"{AppInfo.Name}.db");
}
return Preferences.Get(nameof(DatabaseName), $"{AppInfo.Name}.db");
}
set => Preferences.Set(nameof(DatabaseName), value);
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.