5

When using this code I get the above error:

        var userSettings = new UserSettings()
        {
            Username = TextBox_Username.ToString(),
            Password = TextBox_Password.ToString(),
            Operator = OperatorList.O2
        };

        var settings = IsolatedStorageSettings.ApplicationSettings;
        settings.Add("UserSettings", userSettings);
        settings.Save();

I'm not sure why? though.

deanvmc
  • 5,957
  • 6
  • 38
  • 68

1 Answers1

12

Fixed it. Any stored class needs to be marked as public marking classes internal is not allowed. The issue happened because C# does not default to public scope with new classes.

deanvmc
  • 5,957
  • 6
  • 38
  • 68
  • 3
    Thanks for posting your answer! – theChrisKent Nov 17 '10 at 21:33
  • 2
    Beware: you should not call Save explicitly. The documentation says "On Silverlight for Windows Phone, IsolatedStorageSettings() is not thread safe and throws an IsolatedStorageException when Save() is called." (read here: http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragesettings(v=VS.95).aspx ). Even if said exception is not always raised, I would avoid it. Anyways ApplicationSettings are saved automatically when the application shutdowns. – Francesco De Vittori Nov 18 '10 at 07:28
  • 1
    And be aware of property setters as well. They shouldn't be private – Pashec Oct 21 '12 at 16:53