title: Xamarin.Mac Using security-scoped bookmarks
body: <p>Microsoft's official documentation says:</p>
  <p><a href="https://docs.microsoft.com/en-us/xamarin/mac/app-fundamentals/sandboxing#using-security-scoped-bookmarks" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/xamarin/mac/app-fundamentals/sandboxing#using-security-scoped-bookmarks</a></p>
  <p>to try to access persistent outside of SandBox, but it doesn't work.</p>
  <p>First, I use <code>NSSavePanel.SavePanel</code> according to the SandBox security policy and bookmark the URL that I can access.</p>
  <pre class="lang-cs prettyprint-override"><code>using (var dlg = NSSavePanel.SavePanel)
  {
    dlg.AllowedFileTypes = new[] { &quot;zip&quot; };
    dlg.Prompt = &quot;Authenticate&quot;;
  
    if (dlg.RunModal() &gt; 0)
    {
      NSError error;
      NSData url = dlg.Url.CreateBookmarkData(NSUrlBookmarkCreationOptions.WithSecurityScope, null, null, out error);
    }
  }
  </code></pre>
  <p>And then I retrieve the access-authenticated bookmarks and make them accessible.</p>
  <pre class="lang-cs prettyprint-override"><code>NSData data = new NSData();
  NSUrl url = NSUrl.FromBookmarkData(data, NSUrlBookmarkResolutionOptions.WithSecurityScope, null, out bool isStale, out NSError error);
  
  url.StartAccessingSecurityScopedResource();
  
  //...
  
  url.StopAccessingSecurityScopedResource();
  </code></pre>
  <p>However, the above <code>url</code> will only contain <code>null</code>, which will result in an error.</p>
  <p>How can I make it work?</p>
  <p>Do we need to put anything in the value of <code>NSData data</code> in the first place?</p>