Search code examples
windows-storexafdesktop-bridge

Error Message: Access to the path 'C:\Program Files\WindowsApps is denied


I distributed my xaf Winforms+Desktop Bridge app to myself via the Windows Store.

following this blog

From the blog, I want to pre-generate the ModelAssembly.dll, Model.Cache.xafml and ModulesVersionInfo file and package them to go in the output directory.

These files are generated by XAF if they don't already exist.

Where the output directory is given by

Path.GetDirectoryName(GetType().Assembly.Location)

When I install and run my app from the store. I get this error message.

Access to the path 'C:\Program Files\WindowsApps\JobTalk.JobTalk_1.0.19.0_x64__8kpaqbvntb9aj\SBD.JobTalk.Workflow.Win10\ModelAssembly.dll' is denied.

In the code I tried looking form Path.GetRelativePath but it is not available in Framework 4.7.2

looking for path.getrelativepath


Solution

  • In short, UWP app doesn't allow to access files via absolute path. Because UWP apps run in sandbox and have very limited access to the files out of the app container. In most scenarios, the UWP app can directly access only their install folder and their application data folder. Since the converted app also is a UWP app, so your app need to follow this rule.

    Please check the Prepare to package a desktop application. The document has mentions some scenarios that is related to your question.

    Your application writes to the AppData folder or to the registry with the intention of sharing data with another app. After conversion, AppData is redirected to the local app data store, which is a private store for each UWP app.

    Your application writes to the install directory for your app. For example, your application writes to a log file that you put in the same directory as your exe. This isn't supported, so you'll need to find another location, like the local app data store.

    Here, there's a special scenario that you could access files via files absolute path. It's a restricted capability called as broadFileSystemAccess. Once you add the broadFileSystemAccess capability, you could use the APIs in the Windows.Storage namespace to get all files that the user has access to. Please read File access permissions for more information.

    Please note that the document has explained:

    If you submit an app to the Store that declares this capability, you will need to supply additional descriptions of why your app needs this capability, and how it intends to use it.