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

Error with new LocalStorage instance #26

Open
ahmedsaidzahran opened this issue Feb 12, 2019 · 4 comments
Open

Error with new LocalStorage instance #26

ahmedsaidzahran opened this issue Feb 12, 2019 · 4 comments

Comments

@ahmedsaidzahran
Copy link

JsonReaderException: Additional text encountered after finished reading JSON content: c. Path '', line 1, position 2.

using (var storage = new LocalStorage())

it worked fine but when used .Clear() it crashed, also I used the new release v2.0.0-beta-2 but nothing

@hanssens
Copy link
Owner

The error you mentioned occurred in older versions. However, it should be resolved in v2.0.0-beta-2.
I'm really interested in getting to the bottom of this and make sure it's not a regression issue.

@ahmedsaidzahran Do you have additional info, or a code sample, that helps me reproduce the problem?

@MuhammadAbdelsalam
Copy link

@hanssens and @ahmedsaidzahran, The issue is related to using(){}. The storage object is not destroyed so it is overrated by the new object that was created in an inner method that responsible for storing the value. you will find below my examples for the issue and my solution.

Issue Ex:

  using (var storage = new LocalStorage())
            {
                
                if(storage.Exists(Strings.Token))
                {
                    return storage.Get(Strings.Token).ToString();
                }
                else
                {
                    GenerateToken().Wait();
                    return storage.Get(Strings.Token).ToString();

                }
            }

Soultion:

           var storage = new LocalStorage();
            if (storage.Exists(Strings.Token))
            {
                return storage.Get(Strings.Token).ToString();
            }
            else
            {
                GenerateToken().Wait();
                return storage.Get(Strings.Token).ToString();

            }

@MuhammadAbdelsalam
Copy link

@hanssens, I suggest we could convert the Storage property to be static.

@hanssens
Copy link
Owner

I can't reproduce the problem you mention. Is there any way you @ahmedsaidzahran or @MuhammadAbdelsalam can provide me with an example?

Something like for example this Clear() test would be great as a reusable example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants