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

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

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.

Xavier's answer explains what was going wrong. The reason it happened on my project was that I missed the step of marking the linked files as "Copy if newer"

Related

Xamarin Forms how to Save a file to a location where it can be copied off of the original device

My Xamarin forms app required the user to perform a certain amount of configuration before it can be used. Additionally, the app can be run on multiple computers by the same user (There are valid business reasons for doing this.) What I would like to be able to do is backup the configuration of the app to a file that can then be used on another device to automatically configure the app on the new device in exactly the same way. This will prevent the users from re-entering all the configuration information on each device where they wish to run the app.
Something to keep in mind:
It needs to work on all supported Xamarin Forms platforms - UWP, Android, iOS and Mac.
The app itself does not required the device to have a network connection.
The file needs to be savable in a place where the user can access / copy it to another device (i.e. a USB drive, a network share etc.)
What I have tried:
I have tried using the FilePicker plug in but could not get it to save to anywhere outside the application. (A user trying to find the folder here would not be easy.) Saving anyplace else I received an Access Denied error.
I have tried using the System.IO namespace but encountered the same Access Denied error when saving the file to a someplace outside the application.
I guess my last resort would be to display the configuration information in a XF editor control or such or just copy it to the clipboard (if possible) and have the user manually save the data to a file outside of the application. Does anyone have any other suggestions on how this can be handled?
So after trying multiple things and looking at possible solutions, I could not find a way to easily do this. Instead I used the Xamarin Essentials clipboard function and copied the contents of the file into the clipboard. I then display a message to the user telling them to past the clipboard contents into a file. This seemed to be the best I could do for now.

Converted UWP... Nothing Happens

I have converted a Win32 Application to UWP using MakeAppX and it doesn't seem to run. When I click the icon in the start menu literally nothing happens except a busy icon briefly appears on the cursor.
I completed the same process with Notepad++ and all it's DLLs and that worked fine (using the exact same manifest file, just changing the exe)
My questions are:
Where does the UWP save files that it creates/temporary files etc? If I run an executable and it generates files next to it, where would that be when you run a UWP?
Can I set that location in the AppxManifest?
Is there anyway to see if it has run correctly or not?
Edit:
Could this be a file permissions issue? My application needs to write to 'C:\MyFolder' & creates a folder with a load of files next to the executable upon startup and that doesn't happen.
So looking into this a bit more I came across this blog which discusses preparing for conversion. I think the above file accesses probably contravene the following:
Your app writes to the install directory for your app. For example, your app 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.
This looks like a fairly halting issue, am I correct in that assumption?
If your app is writing to the install directory you will need to change that code to write to your local app data folder instead, as the preparation guide calls out.
Write operations to the install directory are not allowed in order to ensure the ability for the app deployment stack to perform seamless, differential updates and clean uninstalls of your app.
Btw, to debug through your app launch failures you can do the following in Visual Studio: Debug -> Other Debug Target -> Debug Installed App Package -> select your app from the list of installed apps.

Automatically correct .vs/config/applicationhost.config

Visual Studio 2015 has moved the IIS Express configuration file from My Documents into its own hidden .vs directory and tells IISExpress.exe to use that configuration file.
While this may sound like a good idea when you have multiple web applications with conflicting configurations, in fact it's not when you have web applications with custom configurations at all. Because this config file is in a temporary directory which can be deleted when checking out code into a new location from source control, or when cleaning up things in general.
The old location in the Documents folder is a central location and files there usually won't be deleted. If I need to make some changes to this file, like allowing the application to use Windows authentication, I edit this file once and I'm done. Now with the new location, I may need to make these changes multiple times. And since there's two config files (the old location still exists for me), it's even more confusing.
Then you shouldn't commit anything from .vs into version control, so it's not even possible to share these customisations with other team members.
What is the recommended way to update the applicationhost.config file so that it provides the environment required by the web application? Is there a tool that can run in a pre/post build step? Is there a customisation XML file that can be merged into the default file from .vs?
Is it possible at all to just check out a web application from source control and let it work in a local IIS Express? Or will it always require manual corrections after getting the code and web.config?
PS: I've forgotten one thing: There's the <UseGlobalApplicationHostFile> element in the project file which can be set to true, but as soon as I do that, I get an access denied error message every time I want to start the web application. So that doesn't seem to work well.

Where should a .NET Web Application store it's (non database) setting

I am building a Web Application that will be installed many times. The application needs to be able to save certain setting itself upon request.
I have an installer (InnoSetup) but I want to very careful about what permissions I give the Web Application.
I can't use a database.
A default install always leaves the web.config as read-only. (Most secure)
The registry can be problematic. Unless there is a set of keys a DotNet webapp can always write to by default (IIS_IUSR)...
I was considering App_Data, but the default permissions are no longer useful and Inno-Setup can't easily fix it correctly:
https://support.microsoft.com/en-us/kb/2005172
Security and Ease of Setup are both big issues..
I also don't want to make a mess of the machines I install to.
A FAILED solution was to write to the user portion of the registry:
Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\\MyCo\\MyApp\\");
var reg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\MyCo\\MyApp", true);
reg.SetValue("MyValue", (string)dataString, Microsoft.Win32.RegistryValueKind.String);
But I found out that writing to HKEY_CURRENT_USER is also not allowed by default on Server 2012 and likely others. The server error page is helpful and gives options such as explicitly giving the IUSR_{MachineName} explicit permission but this is a no go for me.
So my final solution is to have the installer create a user configurable folder and then assigning all users Read/Write access to that folder. The administrator can always lock it down more if they want.
If anyone has a better option then let me know.
With InnoSetup I created a new Wizard page to suggest and collect a Data folder from the user. The installer then:
Created that folder and gave All Users Read/Write access,
Added a HKLM registry key telling the Web App where to look for the folder,
Notified the user that they should lock the folder down further to prevent abuse.

Does Adobe Air have unconstrained file system access?

I've found several examples and documentation that show how to read and write files on the system, but all show user intervention or reading/writing files in user profile directories. There are a few things I want to do:
Monitor system and other application log files for changes, then automatically load those files when changes occur
Reload a previously open file when the application launches
Write files into a log directory, which probably will not exist in the same path as the application.
In my very quick search, it seems that there may be a security model that constrains an AIR application's access to the file system, so that files can only be read or written to directories selected by the user with the file system dialog OR files can be written within the user profile or air application directory.
Does an Adobe Air application have unconstrained access to the file system?
AIR has exactly the same access to the file system as the current User. If you are admin on your computer, AIR har full access to all files. If you are a restricted user, AIR has restricted access.
One thing to be mindful of is that if you load swf:s from the AIR app's home directory, it will be run in the Application sandbox. If you read it from outside, it will be executed within a File sandbox which is essentially the same as loading from the web.
Some comments on your list:
1 Monitor system and other application log files for changes, then automatically load those files when changes occur
As far as I know, AIR cannot monitor the file system. You will have to poll this regularly.
2 Reload a previously open file when the application launches
Save this info in a file or SQLite and check it when the app starts.
3 Write files into a log directory, which probably will not exist in the same path as the application.
The main thing to remember is to use the file path abstractions in AIR rather than OS specific paths such as c:/
I would say your answer depends on the platform. I'm sure that Adobe Air does not automatically have root access on OS X, so it would not be able to read, write and execute in cases where whatever owner started the AIR app did not have the right permissions for accessing a file. In short, you probably have the same privileges any other program running on the computer might have that was installed by the same user.
More information here:
http://help.adobe.com/en_US/AIR/1.5/devappshtml/WS5b3ccc516d4fbf351e63e3d118666ade46-7f05.html#WS5b3ccc516d4fbf351e63e3d118666ade46-7e35

Resources