jamesmontemagno / SettingsPlugin

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

Method 'Plugin.Settings.Abstractions.ISettings.GetValueOrDefault' not found. #35

Closed Thijmen closed 7 years ago

Thijmen commented 7 years ago

I am using Xamarin.Forms 2.3.3.175. On iOS it works perfectly, yet on Android I get this message directly, without even seeing ui elements in my app.

public static string GeneralSettings
        {
            get
            {
                return AppSettings.GetValueOrDefault<string>(SettingsKey, SettingsDefault);
            }
            set
            {
                AppSettings.AddOrUpdateValue<string>(SettingsKey, value);
            }
        }

Bug

Version Number of Plugin:2.5.1.0 Device Tested On: Simulator Tested On: Accelerated x86 (default Visual Studio for Mac)

Expected Behavior

I can get a value from settings.

Actual Behavior

Before even accessing the string, I get "Method 'Plugin.Settings.Abstractions.ISettings.GetValueOrDefault' not found."

Steps to reproduce the Behavior

Install the plugin in the PCL and Android. I run it, and get this error.

jamesmontemagno commented 7 years ago

Perhaps try to uninstall and re-install the nuget. I can't repo.

Thijmen commented 7 years ago

I saw your project in #37 and went ahead and downloaded it. The only big difference I see is in my Android-project packages.config Yours:

  <package id="Xam.Plugins.Settings" version="2.5.1.0" targetFramework="monoandroid71" />

Mine:

  <package id="Xam.Plugins.Settings" version="2.5.1.0" targetFramework="monoandroid50" />

When I manually change "monoandroid50" to "monoandroid71", I get errors like "System.TypeLoadException: Could not resolve type with token 010001b8".

Yet, in my Android-project packages.config I have other plugins with "monoandroid71". @jamesmontemagno , could you shed a light on this?

Thijmen commented 7 years ago

Update After some tweaking with Android-build settings (Compile using Android version, minimum android target etc) I got it working. Thanks for the great package @jamesmontemagno !

jamesmontemagno commented 7 years ago

That attribute is automatically set based on the version of Android that you are compiling against at the time of package install. This means you are compiling against Android 5.0, which should be fine, however be aware that some projects may be built against newer versions of Android.

michaelmairegger commented 7 years ago

@Thijmen What was the solution in your case? The project in #37 works.

Update By cleaning the solution the issue is now resolved

ahmedelashkerpersonal commented 7 years ago

I had the same problem. Apparently I had removed the nuget package from the android project and installed it separately at some later stage. Making the library version in android different from the ones imported at other projects.

Installing the same version got the project and running again finally.

dfoulk commented 7 years ago

I ran into this after updating to 3.0.1 today. As @jamesmontemagno said, reinstall the package...

Method 1 Keeps your source control history clean

1) Delete the 'packages' folder in your root folder (where your NuGet packages are stored locally) 2) Restart Visual Studio

OR

Method 2 May clutter your source control history

Use the this guide to reinstall.