jamesmontemagno / SettingsPlugin

Read and Write Settings Plugin for Xamarin and Windows
MIT License
324 stars 80 forks source link

System.NullReferenceException: Object reference not set to an instance of an object. #53

Closed riandesign closed 7 years ago

riandesign commented 7 years ago

I have this model:

public class User {
    public string Name;
}

And the settings are:

private const string LoggedUserKey = "loggeduser_key";
private static readonly User LoggedUserDefault = null; // I also tried new User();

public static User LoggedUser {
    get { return AppSettings.GetValueOrDefault<User>(LoggedUserKey, LoggedUserDefault); }
    set { AppSettings.AddOrUpdateValue<User>(LoggedUserKey, value); }
}

In the constructor of my MainPageViewModel, I have this:

if (Settings.LoggedUser != null) {
    Debug.WriteLine("User is not null");
}

But I got this error: System.NullReferenceException: Object reference not set to an instance of an object.

jamesmontemagno commented 7 years ago

The library does not support complex data structures, you can save string, int, bool, etc.. read the readme