简体   繁体   中英

c# App config settings windows 8 - access to tmp file denied

This question was originally posted as "Error occurred loading a configuration file: Access to path c:\\Program Files (x86)\\… denied", but I didn't have much success finding a solution.

My application was written on Windows 7, it's a 32-bit application written with Visual Studio 2010. When I try to deploy this application on a Windows 8 system, the app fails during form_Load, with an error about access to a tmp file in the EXE's directory. I am not creating this temp file directly, but it has a name which is consistent with one generated by the C# GetTempFileName method. The name of the EXE config file (MyApp.exe.config) is also referenced in the error message.

I use the ConfigurationManager to store all of my application settings at startup, so I'm guessing that it is somehow related to this. If I build the application on a Windows 8 system it runs fine on the Windows 8 system, but generates the same error if deployed on a Windows 7 system. I don't know yet exactly what line of code is causing the error but the calls boil down to

System.Configuration.Configuration config =
            ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

config.AppSettings.Settings.Add(settingName, settingValue);

config.Save();

ConfigurationManager.RefreshSection("appSettings");

Both the Windows 7 and 8 systems are 64-bit but the application is 32-bit. Thanks in advance for any advice in solving this.

I use the Settings class to handle the configuration data and the TEMP variable is what I expect it to be, my user\\AppSettings\\Local\\Temp.

The problems encountered were on an evaluation version of Windows 8, this was all that was available. Running the application on a licensed version of Windows 8 Pro it works perfectly.

Thanks for the replies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM