title: How to get Sqlite Connection in Xamarin Forms in iOS?
body: <p>I've created a Xamarin.Forms PCL project and trying to access the local data stored in sqlite database which is working file in Android but not working in iOS. Whenever I'm trying to call the iOS specific code using DependencyService it throws System.NullReferenceException: Object reference not set to an instance of an object.</p>
  
  <p>Here is my calling statement</p>
  
  <pre><code>var db = DependencyService.Get&lt;IDBPath&gt;().GetDBPath();
  </code></pre>
  
  <p>Here is my iOS specific code for getting Sqlite Connection</p>
  
  <pre><code>using SQLite.Net;
  using SQLite.Net.Async;
  using SQLite.Net.Platform.XamarinIOS;
  using SwachhParyatanApp.iOS;
  using System;
  using System.IO;
  
  [assembly: Xamarin.Forms.Dependency(typeof(DBPath_iOS))]
  
  namespace SwachhParyatanApp.iOS
  {
      class DBPath_iOS
      {
          public SQLiteAsyncConnection GetDBPath()
          {
              var sqliteFilename = "localData.db";
              string folder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
              string libraryPath = Path.Combine(folder, "..", "Library");
              var path = Path.Combine(libraryPath, sqliteFilename);
              var platform = new SQLitePlatformIOS();
              var param = new SQLiteConnectionString(path, false);
              var connection = new SQLiteAsyncConnection(() =&gt; new SQLiteConnectionWithLock(platform, param));
              return connection;
          }
      }
  }
  </code></pre>
  
  <p>I don't think the calling method is going to reach the iOS specific code because I used the break point in iOS specific code but it never came to the break point and it immediately gives the error. I've also tried going to the exception for details but there is no inner exception and in stacktrace it only points to the line which called the method.</p>