Skip to content

Newtonsoft JSON Serialization error #86

@Daniele-Tentoni

Description

@Daniele-Tentoni

Hi all,
I've a problem when trying to retreive some data from barrel. In this code

try 
{
    if(barrel.Exists("profile")) 
{
        var cache = FileSystem.CacheDirectory;
        var data = FileSystem.AppDataDirectory;
        var profile = this.barrel.Get<Profile>("profile");
        return profile ?? new Profile();
    }
} 
catch(Exception e) 
{
    Debug.WriteLine(e.StackTrace);
}

I get the error

Type specified in JSON 'System.Reflection.RuntimeMethodInfo, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' is not compatible with 'System.IntPtr, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. Path 'SaveProfileAction.Method.$type', line 1, position 177.

I've saved a profile before read with

barrel.Add("profile", profile, TimeSpan.FromDays(365));

In my Profile class I've

public class Profile : ObservableObject
{
    [JsonIgnore]
    public Action SaveProfileAction { get; set; }

    private string dream = string.Empty;
    public string Dream
    {
        get => dream;
        set => SetProperty(ref dream, value, onChanged: SaveProfileAction);
    }

    private string name = string.Empty;
    public string Name
    {
        get => name;
        set
        {
            var force = false;
            if (value.Length > 15)
            {
                value = value.Substring(0, 15);
                force = true;
            }

            SetProperty(ref name, value, onChanged: SaveProfileAction);
            if (force)
                OnPropertyChanged();
        }
    }

    private string preferredLocation = string.Empty;
    public string PreferredLocation
    {
        get => preferredLocation;
        set
        {
            var force = false;
            if(value.Length > 30)
            {
                value = value.Substring(0, 30);
                force = true;
            }

            SetProperty(ref preferredLocation, value, onChanged: SaveProfileAction);
            if (force)
                OnPropertyChanged();
        }
    }
}

What I understand from the error is that he try to retreive the SaveActionProfile property in the json string but he can't do that. Any idea?

Sorry for my poor English.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions