jamesmontemagno / SettingsPlugin

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

Unable to store values locally #132

Closed avinash-ramireddy closed 5 years ago

avinash-ramireddy commented 6 years ago

Hi, I am using v2.5.8 from almost 8 months. It was working fine. Today I tried to update few packages and I noticed that Settings plugin is not working. It is giving following exception.

image

As you can see my type is int but showing as !0

Below are my objects

private const string PageTypeKey= nameof(PageTypeKey);
private static readonly ePage PageTypeValue= ePage.NotSet;
public static ePage PageType
 {
    get
    {
      return (ePage)AppSettings.GetValueOrDefault(PageTypeKey, PageTypeValue);
    }
   set
   {
    AppSettings.AddOrUpdateValue(PageTypeKey, (int)value);
   }
}

Here PageTypeValue type is int but showing as !0 which is very strange.

I tried to upgrade to v3.1.1(stable) and in this version it is not storing any value. Every time I open it's (another object which is string ) empty not the one I stored last time.

I will try to make repo as I have more pressing issues in my current project now. Note: I upgraded to vs2017 15.7.1 recently

jamesmontemagno commented 6 years ago

maybe delete the bin/obj and clean and rebuild the solution.

avinash-ramireddy commented 6 years ago

I did many times and it's still happening. I am going to revert to previous commit and check if it is still happening.

jamesmontemagno commented 6 years ago

What is your PageTypeValue ?

jamesmontemagno commented 6 years ago

Can you create a new app and repo it for me with just that one setting so I have a small case to look at.

avinash-ramireddy commented 6 years ago

_Here PageTypeValue type is int but showing as !0 which is very strange._

avinash-ramireddy commented 6 years ago

I am trying to make repo but it's not happening there. That part is not working in live project.

Today I started working on it again to see what exactly is happening. So far I noticed that in debug mode it's crashing with Missingmethod exception as shown in image above and in release mode it's just empty.

Are you clearing when in release mode(meaning I put in release mode and build the solution it stored some value first time and then without uninstalling I build again in release mode. This time it cleared old value).

I am really trying to hard to simulate this.

avinash-ramireddy commented 6 years ago

Forget what I mentioned earlier. I am testing the combinations of debug/release against different versions(live version not the sample). and when I build again and again without uninstalling it's clearing old values (both debug and release) but when I unplug my device and just open the already installed app it's fine.

May be I am missing something here as it's been 8 months. Things might have changed

avinash-ramireddy commented 6 years ago

I don't think it's depending on .NET framework, right?

I didn't migrate to .NET Standard yet, it's still old .NET Framework 4.5

jamesmontemagno commented 6 years ago

Maybe rename your key? Could be corrupt?

What type of project is it? If it is WPF or something that code hasn't changed forever.

avinash-ramireddy commented 6 years ago

I will try that now.

It's xamarin forms. image There is new requirement now and I wanted to update packages first and this happened

avinash-ramireddy commented 6 years ago

I changed key name to something else and it's still happening same way. I am sorry I can't make repo (don't have same old framework anymore and latest is always pointing to create using .net standard while creating project assuming issue depends on the .NET type) and can't provide live version snippets as well.

avinash-ramireddy commented 6 years ago

Sorry, closed by mistake.

CPARKIONSON commented 6 years ago

This may help you: http://www.developersite.org/1000-24593-Xamarin-Forms-overriding-OnAppearing-causes-app-to-crash

I’ve been researching trying to figure out my own error, but mine is DateTime related and lack of personal experience. Hope that site helps you!

ryanherman commented 6 years ago

I lied. I had other issues.

avinash-ramireddy commented 6 years ago

I went through the above link. But my key is not null.

garie commented 6 years ago

I am seeing this issue as well. Investigating, will update...

garie commented 6 years ago

I am updating from Xam.Plugins.Settings nuget package 3.1.1 to 4.0.0.7. That is the only change I have made.

In my Android and iOS csproj files, it removed the reference to Plugin.Settings.Abstractions. This dll is not in any of the folders in my packages/Xam.Plugins.Settings.4.0.0.7/lib folder, but it is in all of the folders in my packages/Xam.Plugins.Settings.3.1.1/lib folder.

Error:

Unhandled Exception:
System.MissingMethodException: Plugin.Settings.Abstractions.ISettings Plugin.Settings.CrossSettings.get_Current()
at MyProject.SharedComponents.Services.Settings.get_IsLoadingDataFromBackup () [0x00000] in 

Code:

        public static bool IsLoadingDataFromBackup
        {
            get => AppSettings.GetValueOrDefault(nameof(IsLoadingDataFromBackup), false);
            set => AppSettings.AddOrUpdateValue(nameof(IsLoadingDataFromBackup), value);
        }

I have tried changing the name IsLoadingDataFromBackup to no avail. I also tried making it a Boolean instead of a bool but that did not help. I am able to use GetValueOrDefault with some other settings (int, string) that do not cause this issue, which may explain why you are unable to reproduce. Have you tried a bool setting?

I believe the problem is the missing dll and reference.

jamesmontemagno commented 6 years ago

Uninstall and re-insall all yours and do a clean/rebuild.

garie commented 6 years ago

It doesn't look like Xam.Plugins.Settings 4.0.0.7 is available on nuget anymore.

jamesmontemagno commented 6 years ago

use the newer pre-releases.

DigitalJo commented 5 years ago

Is this fixed? i am facing the same problem