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!
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..
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"));
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With