xamarin - XLabs.Platform not working on UWP -


i using windows 10 & visual studio 2015 development , targeting android, ios, windows phone, windows universal.

i wanted use xlabs securestorage service.

i using xlabs.platform package 2.3.0-pre02.

at line getting exception (only uwp)

securestorage.store(key, encoding.utf8.getbytes(value)); 

and exception details :

filename : system.runtime.windowsruntime, version=4.0.11.0, culture=neutral, publickeytoken=b77a5c561934e089

hresult : -2146234304

helplink : null

innerexception : null

message : not load file or assembly 'system.runtime.windowsruntime, version=4.0.11.0, culture=neutral, publickeytoken=b77a5c561934e089' or 1 of dependencies. located assembly's manifest definition not match assembly reference. (exception hresult: 0x80131040)

source : xlabs.platform.uwp

sourcetrack : @ xlabs.platform.services.securestorage.d__6.movenext() @ system.runtime.compilerservices.asyncvoidmethodbuilder.starttstatemachine @ xlabs.platform.services.securestorage.store(string key, byte[] databytes) @ uwptest.securestorageservice.store(string key, string value, boolean overwrite)

after trial , error able run securestorage service on xamarin uwp.

securestorage.cs(code)

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks;  namespace abc.uwp.common {      using system;      using system.io;      using windows.storage;      using system.threading;      using system.runtime.interopservices.windowsruntime;      using xlabs.platform.services;      using windows.security.cryptography.dataprotection;       /// <summary>      /// implements <see cref="isecurestorage"/> wp using <see cref="isolatedstoragefile"/> , <see cref="protecteddata"/>.      /// </summary>      public class securestorage : isecurestorage      {          private static windows.storage.applicationdata appstorage { { return applicationdata.current; } }           private static windows.security.cryptography.dataprotection.dataprotectionprovider _dataprotectionprovider = new dataprotectionprovider();           private readonly byte[] _optionalentropy;           /// <summary>          /// initializes new instance of <see cref="securestorage"/>.          /// </summary>          /// <param name="optionalentropy">optional password additional entropy make encyption more complex.</param>          public securestorage(byte[] optionalentropy)          {              this._optionalentropy = optionalentropy;          }           /// <summary>          /// initializes new instance of <see cref="securestorage"/>.          /// </summary>          public securestorage() : this(null)          {           }           #region isecurestorage members           /// <summary>          /// stores specified key.          /// </summary>          /// <param name="key">the key.</param>          /// <param name="databytes">the data bytes.</param>          public async void store(string key, byte[] databytes)          {              //var mutex = new mutex(false, key);              using (var mutex = new mutex(false, key))              {                  try                  {                      mutex.waitone();                       var buffer = databytes.asbuffer();                       if (_optionalentropy != null)                      {                          buffer = await _dataprotectionprovider.protectasync(buffer);                      }                       var file = await appstorage.localfolder.createfileasync(key, creationcollisionoption.replaceexisting);                       await fileio.writebufferasync(file, buffer);                  }                  catch (exception ex)                  {                      throw new exception(string.format("no entry found key {0}.", key), ex);                  }              }              //finally              //{              //    mutex.releasemutex();              //}          }           /// <summary>          /// retrieves specified key.          /// </summary>          /// <param name="key">the key.</param>          /// <returns>system.byte[].</returns>          /// <exception cref="system.exception"></exception>          public byte[] retrieve(string key)          {              var mutex = new mutex(false, key);               try              {                  mutex.waitone();                   return task.run(async () =>                  {                      var file = await appstorage.localfolder.getfileasync(key);                      var buffer = await fileio.readbufferasync(file);                      if (_optionalentropy != null)                      {                          buffer = _dataprotectionprovider.unprotectasync(buffer).getresults();                      }                      return buffer.toarray();                  }).result;              }              catch (exception ex)              {                  throw new exception(string.format("no entry found key {0}.", key), ex);              }                           {                  mutex.releasemutex();              }          }           /// <summary>          /// deletes specified key.          /// </summary>          /// <param name="key">the key.</param>          public void delete(string key)          {              var mutex = new mutex(false, key);               try              {                  mutex.waitone();                   task.run(async () =>                  {                      var file = await appstorage.localfolder.getfileasync(key);                      await file.deleteasync();                  });              }                           {                  mutex.releasemutex();              }          }           /// <summary>          /// checks if storage contains key.          /// </summary>          /// <param name="key">the key search.</param>          /// <returns>true if storage has key, otherwise false.     </returns>          public bool contains(string key)          {              try              {                  return task.run(async() => await  appstorage.localfolder.getfileasync(key)).result.isavailable;              }              catch              {                  return false;              }          }          #endregion      }  } 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -