Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access is denied despite using broadFileSystemAccess

Tags:

c#

manifest

uwp

UWP is killing me.....

I had to reinstall VisualStudio2017 after a computer crash. And now, my app that was working perfectly well before the crash refuses to work.

I've been using the broadFileSystemAccess capability in the Package Manifest, as per the instructions in the MS documentation:

 xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
 IgnorableNamespaces="rescap uap mp desktop4 iot2">

and

<Capabilities>
<rescap:Capability Name="broadFileSystemAccess" />
</Capabilities>

This worked no problem, but now I get an underlined rescap:Capability and the compile warning "The element 'Capabilities' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' has invalid child element 'Capability' in namespace .......

Since it's a warning, it compiles without a hickup. However, the application cannot access files (access denied) justa s if this manifest code wasn't there.

I'm holding back saying bad words.... anybody has any idea of what is causing this? It's a fresh VS2017 install.

Thanks!

like image 407
Francois Gagnon Avatar asked Nov 28 '18 11:11

Francois Gagnon


3 Answers

Ok so heres some of my findings.

1. an app must not declare both broadFileSystemAccess and any of the other three file-system capabilities. (Pictures, documents, downloads)

source: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/415d02da-eeb6-45b3-b6e2-946b124d14b0/broadfilesystemaccess-issue?forum=wpdevelop

2. This only works with the storageFile api NOT File.Exists etc api

source: https://learn.microsoft.com/en-gb/windows/uwp/packaging/app-capability-declarations

3. Make sure the fileAccess is enabled as with the other two answers:

source: https://stackoverflow.com/a/57703368/2987066

4. I also found that every time I started debugging (and the code had changed) I needed to turn that setting on and off again to get it to work

source: frustratingly debugging the application through trial and error

Thanks microsoft for your excellent development environment, it really shows how much developers love developing your apps as your store is really flourishing in comparison to your competitors... oh wait..

like image 96
User1 Avatar answered Oct 10 '22 23:10

User1


Thank you for reporting this issue. It's a known issue in 1809. The relevant team is working on it.

Clint Rutkas has replied on this thread: No user-consent prompt on first run of broadFileSystemAccess-capable UWP app.

He suggested that we could use try/catch to catch this scenario:

try
{
    StorageFile storageFile = await StorageFile.GetFileFromPathAsync(@"E:\Foo");
}
catch (Exception)
{
    // prompt user for what action they should do then launch below
    // suggestion could be a message prompt
    await Launcher.LaunchUriAsync(new Uri("ms-settings:appsfeatures-app"));
}
like image 3
Xie Steven Avatar answered Oct 10 '22 21:10

Xie Steven


You also need to allow your app access to the file system in Settings. This a safety measure so the user of the machine acknowledges your app can have access outside the controlled access to files provided by the UWP app container it runs in.

enter image description here

like image 1
Zodman Avatar answered Oct 10 '22 22:10

Zodman