Search code examples
c#macosxamarinxamarin.macxamarin.essentials

C# , Xamarin.Essentials Secure Storage


After reviewing my options regarding saving JWT token, I chose Xamarin.Essentials Secure Storage.

Problem being that my app always breaks when trying to save a token within the storage with the following error:

"System.AggregateException has been thrown"

The details are as follow:

"Xamarin.Essentials.NotImplementedInReferenceAssemblyException

This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation."

This clearly means that something went wrong in the installaion of the nuget package, so I:

  • Uninstalled and reinstalled the xamarin.essentials package.
  • Upgraded .Netstandard to 2.0, thinking that 1.6 wasn't compatible.
  • Checked if the package is referenced within the csproj file.

So forth, nothing.

For now, I have a TokenStorageController with the following lines of codes :

    public bool SaveToken(string token)
    {
        if(token != null)
        {
            Preferences.Set(key, token);

            if(Preferences.ContainsKey(key))
            {
                return true;
            }
        }    
        return false;
    }

The RestService class from where the controller gets called looks like this :

        //await SecureStorage.SetAsync("oauth_token", "booommmmmm"); // changed to this simply to check if my controller was the problem
        TokenStorageController tokenStorage = new TokenStorageController();
        await tokenStorage.SaveToken("boommmmm"); // where I get an error

And here is the exact line where the error occurs:

      var loginTask = Task.Run(() => restService.LoginAsync(user)).Result;

If no solutions, I will remove all packages and reinstall them all. ONE BY ONE! I swear I'll do it! And if no solutions at all, I will store the token within SQL as I already have a controller in place to do so.

I am a Xamarin and C# noob so bear with me please.

FYI: I am using a macOS client for testing purposes, as the cause could be that SecureStorage doesn't work for macOS apps.

Thanks!


Solution

  • Xamarin.Mac is not currently a supported platform, just iOS, Android, UWP.

    The code is available for review at: