title: Accessing file in UWP throws UnauthorizedAccessException even with access granted
body: <p>I'm trying to browse files and send them to a service, and for that I'm making a small internal utility app in UWP.</p>
  <p>I made a POC console application and everything works fine.</p>
  <p>Now I'm in an UWP app and I get an <code>System.UnauthorizedAccessException</code> when executing the same code.</p>
  <p>I must add, the exception comes from a package I'm using (but I'm not developing), I'm assuming since it works in the console app and not the UWP app, the error is from my end, still, here is the complete error message :</p>
  <pre><code>An exception of type 'System.UnauthorizedAccessException' occurred in System.Private.CoreLib.dll but was not handled in user code
  Access to the path 'D:\pulseinvoices\uk_00003.pdf' is denied.
  </code></pre>
  <p>I have authorized the app in the filesystem privacy settings
  <a href="https://i.stack.imgur.com/LRODx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LRODx.png" alt="enter image description here" /></a></p>
  <p>And I have done the same in the manifest :</p>
  <pre><code>&lt;Package
    xmlns=&quot;http://schemas.microsoft.com/appx/manifest/foundation/windows10&quot;
    xmlns:mp=&quot;http://schemas.microsoft.com/appx/2014/phone/manifest&quot;
    xmlns:uap=&quot;http://schemas.microsoft.com/appx/manifest/uap/windows10&quot;
    xmlns:rescap=&quot;http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities&quot;
   
    IgnorableNamespaces=&quot;uap mp rescap&quot;&gt;
  
  ...
  
    &lt;Capabilities&gt;
      &lt;rescap:Capability Name=&quot;broadFileSystemAccess&quot; /&gt;
      &lt;Capability Name=&quot;internetClient&quot; /&gt;
      &lt;uap:Capability Name=&quot;documentsLibrary&quot;/&gt;
    &lt;/Capabilities&gt;
  </code></pre>
  <p>I've read somewhere that setting the file as an environment variable is also necessary. This would completely defeat the purpose of file picking (if users are required to set an environment variable every time they need to pick a file, that's just not practical), but hey, I'm open to suggestions, so I also did this :</p>
  <p><a href="https://i.stack.imgur.com/7ciKC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7ciKC.png" alt="enter image description here" /></a></p>
  <p>For the sake of being as complete as possible, here is the code that I'm executing :</p>
  <pre><code>private static readonly string FILE = @&quot;D:\pulseinvoices\uk_00003.pdf&quot;;  //Test document
  
  await service.ProcessAndWait(FILE, channel, params);
  </code></pre>
  <p>I'm lost because the console app works fine, executing this code only fails in the UWP app.</p>
  <p><strong>important</strong> : The <code>service</code> object is coming from an external .dll, as I said earlier in the post. I'm still hoping the issue is coming from my end so I can fix it. So I have the path using <code>StorageFile</code>, but when that .dll is trying to access it, I get the exception. That .dll is in my solution, so it should have the same access rights as the solution, correct?</p>
  <p>Everything is hardcoded, this is pretty much a one-liner app at this stage. The only difference is that it's running in UWP vs Console.</p>
  <p>What are my options?</p>
  <p>EDIT : Adding some more details for clarity.</p>
  <p>Here is how I fetch the file in the first place, before using the external .dll to process it.</p>
  <p><a href="https://i.stack.imgur.com/jT9TS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jT9TS.png" alt="enter image description here" /></a></p>
  <p>Behind <code>selectFile</code>, a custom object is created with the path of the file among other things, so I do have a <code>StorageFile</code> object that is usable within my UWP app at that point. It's only once I use that external .dll and with <code>file.Path</code> that it fails. If I don't use the storage file at all and just hardcode the path I have the same exception. My solution can access the file, but the .dll within that solution cannot ?</p>