title: Cross-platform solution to isolated storage in PCL?
body: <p>I'm currently using the latest version of PCLStorage for my Xamarin app and it doesn't work well in Android. Every time my app loads it is unable to find the directory I had just created. But it works fine in my Windows project. Odd...</p>
  
  <p>Does anyone know of a good alternative compatible with Portable Class Libraries?</p>
  
  <p>Thanks!</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>Here is the code I use:</p>
  
  <p>These are the functions that save/load the data:</p>
  
  <pre><code> public static async Task&lt;bool&gt; LoadPlayerData()
   {
      PlayerData data = await LoadData&lt;PlayerData&gt;("PlayerState.dat");
  
      if (data != null)
      {
          PlayerData.Current = data;
          return true;
      }
      else
          return false;
   }
  
   public static async Task SavePlayerData()
   {
      IFolder dataFolder = await GetDataFolder(true);
      IFile file = await dataFolder.CreateFileAsync("PlayerState.dat", CreationCollisionOption.ReplaceExisting);
  
      string json = await Task.Factory.StartNew(() =&gt; JsonConvert.SerializeObject(PlayerData.Current, Formatting.Indented));
      await file.WriteAllTextAsync(json);
   }
  </code></pre>
  
  <p>These are the functions that do the work using PCLStorage:</p>
  
  <pre><code>    private static async Task&lt;T&gt; LoadData&lt;T&gt;(string filename)
      {
          IFolder dataFolder = await GetDataFolder(false);
  
          if (dataFolder == null)
              return default(T);
  
          IFile file = null;
  
          try
          {
              // Catch the exception if the file doesn't yet exist
              file = await dataFolder.GetFileAsync(filename);
          }
          catch (PCLStorage.Exceptions.FileNotFoundException) { return default(T); }
          catch (System.IO.FileNotFoundException) { return default(T); }
  
          if (file == null)
              return default(T);
  
          string contents = await file.ReadAllTextAsync();
  
          T data = JsonConvert.DeserializeObject&lt;T&gt;(contents);
  
          return data;
      }
  
      private static async Task&lt;IFolder&gt; GetDataFolder(bool createIfNonExistent)
      {
          IFolder rootFolder = FileSystem.Current.LocalStorage;
          IFolder dataFolder = null;
  
          // Save actions will create the folder if it doesn't exist. Load actions will only try to get the folder.
          if (createIfNonExistent)
              dataFolder = await rootFolder.CreateFolderAsync("GameData", CreationCollisionOption.OpenIfExists);
          else
          {
              try
              {
                  // Catch the exception if the folder doesn't yet exist
                  dataFolder = await rootFolder.GetFolderAsync("GameData");
              }
              catch (PCLStorage.Exceptions.DirectoryNotFoundException) { return null; }
          }
  
          return dataFolder;
      }
  </code></pre>
  
  <p>Everything runs fine in my Windows 8 project, but in Android, when trying to load the data which was just created (for example, when re-starting the app), I always get a <strong>DirectoryNotFoundException</strong> in my <strong>GetDataFolder</strong> function.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>On the <strong>SavePlayerData</strong> function I get a successful file creation since it contains the following path:</p>
  
  <blockquote>
    <p>/data/data/com.quickshift/files/GameData/PlayerState.dat</p>
  </blockquote>
  
  <p>When I restart my app, the <strong>GetDataFolder</strong> function fails when calling <strong>rootFolder.GetFolderAsync(...)</strong> with the following message:</p>
  
  <blockquote>
    <p>Directory does not exist: /data/data/com.quickshift/files/GameData</p>
  </blockquote>
  
  <p>I'll keep looking into this, it used to work a few weeks ago and I never changed this code...</p>