.NET "Settings" do not work with 64-bit (InvalidOperationException)

I am building a C # .NET application (VS2010), but I have some problems saving settings (which work fine under 32-bit Windows XP) under 64-bit Windows 7.

I have a Settings.settings parameter in a solution with a parameter check parameter named res112text in, set as a type string in the user area, with an β€œInternal” parameter as an access modifier parameter.

Then save command in

Properties.Settings.Default.res112text = "10002b"; try { Properties.Settings.Default.Save(); } catch (Exception e) { MessageBox.Show(e.GetType().ToString() + " for " + e.Message.ToString()); } 

upon detection, an error type immediately appears:

 System.InvalidOperationException 

and for an exception message:

Method failed with unexpected error code 3

I pack the .dll.config file into the installer and fit perfectly into the program file directory.

Can anyone suggest what might be wrong?

Update: full error:

 Error System.InvalidOperationException: Method failed with unexpected error code 3. at System.Security.AccessControl.NativeObjectSecurity.CreateInternal( ResourceType resourceType, Boolean isContainer, String name, SafeHandle handle, AccessControlSections includeSections, Boolean createByName, ExceptionFromErrorCode exceptionFromErrorCode, Object exceptionContext) at System.Security.AccessControl.FileSecurity..ctor(String fileName, AccessControlSections includeSections) ... at System.Configuration.SettingsBase.Save() at MyAddon.IEModule.ConfigSave() 

Update. There seems to be no workaround when IE Protected Mode is enabled unless all users have manually disabled it.

+4
source share
2 answers

Your problem is probably caused by insufficient permissions to save the file. As suggested by Hans Passant, you should take a look at Isolated Storage: http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile.aspx

The purpose of isolated storage is to allow applications with limited rights to save data. The MSDN page contains sample code that should run you.

+5
source

I can use the Save () method if there is no user.config dll file, but I cannot do the same when it is already there. Therefore, a workaround is probably to delete the "user.config" file manually (which curiously works)

 System.IO.File.Delete(System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoaming).FilePath); 

and then use the Save () method to create a new user.config file. Please let me know if there is a catch, but so far I have not noticed.

0
source

Source: https://habr.com/ru/post/1341889/


All Articles