Skip to content
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

ApplicationData.Current.LocationSettings bug #1276

Closed
2 of 9 tasks
NGame1 opened this issue Jul 21, 2019 · 7 comments
Closed
2 of 9 tasks

ApplicationData.Current.LocationSettings bug #1276

NGame1 opened this issue Jul 21, 2019 · 7 comments
Assignees
Labels
kind/bug Something isn't working platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform

Comments

@NGame1
Copy link

NGame1 commented Jul 21, 2019

Current behavior

My sample code that doesn't work

internal class AppSettingsHelper
    {
        private static StorageFolder AppLocalSettingsFolder => ApplicationData.Current.LocalFolder;
        private static ApplicationDataContainer AppSettings => ApplicationData.Current.LocalSettings;

        public static AppInternalSettingsCore AppInternalSettings => AppSettings.Values["AppInternalSettings"] == null ? new AppInternalSettingsCore() : JsonConvert.DeserializeObject<AppInternalSettingsCore>(AppSettings.Values["AppInternalSettings"].ToString());
        
        public static int ApplicationTheme
        {
            get => AppInternalSettings.ApplicationTheme;
            set
            {
                AppInternalSettingsCore c = AppInternalSettings;
                c.ApplicationTheme = value;
                AppSettings.Values["AppInternalSettings"] = JsonConvert.SerializeObject(c);
            }
        }

        public static bool FirstLaunch
        {
            get => AppInternalSettings.FirstLaunch;
            set
            {
                AppInternalSettingsCore c = AppInternalSettings;
                c.FirstLaunch = value;
                AppSettings.Values["AppInternalSettings"] = JsonConvert.SerializeObject(c);
            }
        }
    }

It fails with the following error
"Operation is not valid due to the current state of the object."
Trace:
" at Windows.Storage.ApplicationDataContainer+SharedPreferencesPropertySet.get_Item (System.String k…"

It has a workaround, fortunately.
Change the below line:
public static AppInternalSettingsCore AppInternalSettings => AppSettings.Values["AppInternalSettings"] == null ? new AppInternalSettingsCore() : JsonConvert.DeserializeObject<AppInternalSettingsCore>(AppSettings.Values["AppInternalSettings"].ToString());
with this one:
public static AppInternalSettingsCore AppInternalSettings => AppSettings.Values.ContainsKey("AppInternalSettings") == false ? new AppInternalSettingsCore() : JsonConvert.DeserializeObject<AppInternalSettingsCore>(AppSettings.Values["AppInternalSettings"].ToString());

Nuget Package:
Package Version(s):V1.46.0-dev2264

Affected platform(s):

  • iOS (Not Tested)
  • Android
  • WebAssembly
  • Windows (Not Tested)
  • Build tasks

Visual Studio

  • 2017 (version: )
  • 2019 (version: )
  • for Mac (version: )

Relevant plugins

  • Resharper (version: )
@NGame1 NGame1 added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels Jul 21, 2019
@ghuntley ghuntley added the platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform label Jul 22, 2019
@ghuntley
Copy link
Member

Howdy @NGame1, can you please provide a project that reproduces this? ie. File -> New Uno Application -> <implement repro in the Android project>

@ghuntley ghuntley added triage/needs-information Indicates an issue needs more information in order to work on it. and removed triage/untriaged Indicates an issue requires triaging or verification labels Jul 22, 2019
@MartinZikmund
Copy link
Member

Does the same code run under UWP without exception?

@NGame1
Copy link
Author

NGame1 commented Jul 22, 2019

@MartinZikmund yes it does. In UWP if it can't find a key it will return null.
@ghuntley Yes I will create a sample repro for you

@no-response no-response bot removed the triage/needs-information Indicates an issue needs more information in order to work on it. label Jul 22, 2019
@MartinZikmund
Copy link
Member

I will try to reproduce in unit tests

@MartinZikmund
Copy link
Member

@NGame1 Can you verify this has been fixed in latest preview build :-) ?

@ghuntley ghuntley added the triage/needs-information Indicates an issue needs more information in order to work on it. label Jul 25, 2019
@NGame1
Copy link
Author

NGame1 commented Jul 25, 2019

@MartinZikmund In reality no. My current project can not run on build 2311.

@no-response no-response bot removed the triage/needs-information Indicates an issue needs more information in order to work on it. label Jul 25, 2019
@ghuntley
Copy link
Member

@NGame1 can you open another issue that shares with us what's preventing you from using build 2311? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform
Projects
None yet
Development

No branches or pull requests

3 participants