title: Failing to Initialize FirebaseDb in a MAUI App for iOS
body: <p>I am trying to access my Firestore database from a MAUI application targeting iOS (using Microsoft tools in an Apple product for Google access; a...peculiar selection of inventory, I know). I am using the NuGet package Google.Cloud.Firestore and trying to initialize an instance of <code>FirebaseDb</code> to access the database but nothing happens. How can I fetch data from a MAUI app targeting iOS? I tried the Xamarin library Plugin.CloudFirestore by f-miyu but cannot make it work in MAUI.</p>
  <p>You can see the code below, and more explanations at the end of this question:</p>
  <pre><code>        public async Task ReadCredentials()
          {
              System.Diagnostics.Debug.WriteLine(&quot;Start reading credentials&quot;);
              using var stream = await FileSystem.OpenAppPackageFileAsync(&quot;FirestoreKey.json&quot;);
              using StreamReader reader = new(stream);
              var contents = reader.ReadToEnd();
              System.Diagnostics.Debug.WriteLine(&quot;Credentials acquired.&quot;);
              jsonCredentials = contents;
  
          }
  
         public void InitDb()
          {
              System.Diagnostics.Debug.WriteLine(&quot;Initializing database builder with credentials&quot;);
              System.Diagnostics.Debug.WriteLine(jsonCredentials);
  
              var dbBuilder = new FirestoreDbBuilder
              {
                  JsonCredentials = jsonCredentials,
                  WarningLogger = (string message) =&gt; System.Diagnostics.Debug.WriteLine(message)
              };
  
              System.Diagnostics.Debug.WriteLine(&quot;Database builder initialized&quot;);
  
              System.Diagnostics.Debug.WriteLine(&quot;Building database&quot;);
              var db = dbBuilder.Build();
              System.Diagnostics.Debug.WriteLine(&quot;Done&quot;);
              if (db != null)
                  System.Diagnostics.Debug.WriteLine(&quot;Database built&quot;);
              else
                  System.Diagnostics.Debug.WriteLine(&quot;FAILED&quot;);
          }
  </code></pre>
  <p>My plist.info file contains the following lines:</p>
  <pre><code>    &lt;key&gt;NSAppTransportSecurity&lt;/key&gt;
      &lt;dict&gt;
              &lt;key&gt; NSAllowsArbitraryLoads&lt;/key&gt;
              &lt;true/&gt;
             
      &lt;/dict&gt;
  </code></pre>
  <p>When I run the above methods in order, the application stops at the line building the database and stops without giving me any warning or error info. The remaining lines are not even called. What I get in the console is:</p>
  <pre><code>Start reading credentials
  Credentials acquired.
  Initializing database builder with credentials
  {
    &quot;type&quot;: &quot;service_account&quot;,
    &quot;project_id&quot;: &quot;&lt;removed&gt;&quot;,
    &quot;private_key_id&quot;: &quot;&lt;removed&gt;&quot;,
    &quot;private_key&quot;: &quot;-----BEGIN PRIVATE KEY-----\n&lt;removed&gt;\n&quot;,
    &quot;client_email&quot;: &quot;&lt;removed&gt;&quot;,
    &quot;client_id&quot;: &quot;&lt;removed&gt;&quot;,
    &quot;auth_uri&quot;: &quot;&lt;removed&gt;&quot;,
    &quot;token_uri&quot;: &quot;&lt;removed&gt;&quot;,
    &quot;auth_provider_x509_cert_url&quot;: &quot;&lt;removed&gt;&quot;,
    &quot;client_x509_cert_url&quot;: &quot;&lt;removed&gt;&quot;
  }
  
  Database builder initialized
  Building database
  2022-05-10 12:38:17.827901+0300 istanbul-bridge-conference-maui[2999:97800] SecTaskLoadEntitlements failed error=22 cs_flags=200, pid=2999
  2022-05-10 12:38:17.828092+0300 istanbul-bridge-conference-maui[2999:97800] SecTaskCopyDebugDescription: istanbul-bridge-[2999]/0#-1 LF=0
  2022-05-10 12:38:17.828353+0300 istanbul-bridge-conference-maui[2999:97800] SecTaskLoadEntitlements failed error=22 cs_flags=200, pid=2999
  2022-05-10 12:38:17.828536+0300 istanbul-bridge-conference-maui[2999:97800] SecTaskCopyDebugDescription: istanbul-bridge-[2999]/0#-1 LF=0
  Thread started:  #14
  Thread started:  #15
  Thread finished: &lt;Thread Pool&gt; #6
  Thread finished: &lt;Thread Pool&gt; #13
  Thread finished: &lt;Thread Pool&gt; #8
  Thread finished: &lt;Thread Pool&gt; #10
  Thread finished: &lt;Thread Pool&gt; #12
  
  </code></pre>
  <p>I am partially following the steps in <a href="https://firebase.google.com/docs/firestore/quickstart#c" rel="nofollow noreferrer">https://firebase.google.com/docs/firestore/quickstart#c</a> . Since I cannot use the environmental variables in iOS as in the link, I am trying to create <code>FirestoreDb</code> using the json key string. If I do not add <code>NSAllowsArbitraryLoads</code> to the plist file, I get the following console output:</p>
  <pre><code>Building database
  2022-05-10 11:51:03.397142+0300 istanbul-bridge-conference-maui[2603:74019] SecTaskLoadEntitlements failed error=22 cs_flags=200, pid=2603
  2022-05-10 11:51:03.397375+0300 istanbul-bridge-conference-maui[2603:74019] SecTaskCopyDebugDescription: istanbul-bridge-[2603]/0#-1 LF=0
  2022-05-10 11:51:03.397657+0300 istanbul-bridge-conference-maui[2603:74019] SecTaskLoadEntitlements failed error=22 cs_flags=200, pid=2603
  2022-05-10 11:51:03.397820+0300 istanbul-bridge-conference-maui[2603:74019] SecTaskCopyDebugDescription: istanbul-bridge-[2603]/0#-1 LF=0
  2022-05-10 11:51:03.398957+0300 istanbul-bridge-conference-maui[2603:74019] [connection] nw_socket_connect [C1:2] connect failed (fd 13) [65: No route to host]
  2022-05-10 11:51:03.399110+0300 istanbul-bridge-conference-maui[2603:74019] [] nw_socket_connect connect failed [65: No route to host]
  2022-05-10 11:51:03.399570+0300 istanbul-bridge-conference-maui[2603:74019] Connection 1: received failure notification
  2022-05-10 11:51:03.399678+0300 istanbul-bridge-conference-maui[2603:74019] Connection 1: failed to connect 1:65, reason -1
  2022-05-10 11:51:03.399767+0300 istanbul-bridge-conference-maui[2603:74019] Connection 1: encountered error(1:65)
  2022-05-10 11:51:03.400501+0300 istanbul-bridge-conference-maui[2603:74019] Task &lt;A19F42B0-05EA-46A5-A038-6F385942DB68&gt;.&lt;1&gt; HTTP load failed, 0/0 bytes (error code: -1004 [1:65])
  2022-05-10 11:51:03.403258+0300 istanbul-bridge-conference-maui[2603:73954] Task &lt;A19F42B0-05EA-46A5-A038-6F385942DB68&gt;.&lt;1&gt; finished with error [-1004] Error Domain=NSURLErrorDomain Code=-1004 &quot;Could not connect to the server.&quot; UserInfo={_kCFStreamErrorCodeKey=65, NSUnderlyingError=0x6000001628b0 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 &quot;(null)&quot; UserInfo={_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface: en0, _kCFStreamErrorCodeKey=65, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask &lt;A19F42B0-05EA-46A5-A038-6F385942DB68&gt;.&lt;1&gt;, _NSURLErrorRelatedURLSessionTaskErrorKey=(
      &quot;LocalDataTask &lt;A19F42B0-05EA-46A5-A038-6F385942DB68&gt;.&lt;1&gt;&quot;
  ), NSLocalizedDescription=Could not connect to the server., NSErrorFailingURLStringKey=http://169.254.169.254/computeMetadata/v1/?recursive=true, NSErrorFailingURLKey=http://169.254.169.254/computeMetadata/v1/?recursive=true, _kCFStreamErrorDomainKey=1}
  </code></pre>