简体   繁体   中英

Settings.Default.Save() does not persist when debugging app in Visual Studio

I have some code that is intended to determine if a setting already exists and get the value if it does.

            exists = Settings.Default.Properties.OfType<SettingsProperty>().Any(p => p.Name == "LastOpenLocation");
        if (!exists)
        {
            SettingsProperty lastOpenLocation = new SettingsProperty("LastOpenLocation");
            lastOpenLocation.PropertyType = typeof(string);
            lastOpenLocation.DefaultValue = casMate.OpenPath;
            Settings.Default.Properties.Add(lastOpenLocation);
            Settings.Default.Save();
        }
        else
        {
            Settings.Default.Properties["LastOpenLocation"].DefaultValue = casMate.OpenPath;
        }

Everything runs fine with no exceptions. The next debug run the settings saves last time do not persist. I want to make sure that settings are persisting before installing the app on production machines. What is the issue? Why do my settings not persist between debug runs?

The answer to this question is... A stack answer I couldn't find initially

I am trying to create a new setting at run time. New settings can only be created at design time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM