Click here to Skip to main content
15,908,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My application threw an exception when it tried to save some user configuration settings by calling 'Properties.Settings.Default.Save()'.

Code:

C#
Properties.Settings.Default.UserProp = "MyUserValue";
Properties.Settings.Default.Save();


The exception is:

System.Configuration.ConfigurationErrorsException was caught
  BareMessage=Failed to save settings: A configuration file cannot be created for the requested Configuration object.
  Line=0
  Message=Failed to save settings: A configuration file cannot be created for the requested Configuration object.
  Source=System
  StackTrace:
       at System.Configuration.ClientSettingsStore.WriteSettings(String sectionName, Boolean isRoaming, IDictionary newSettings)
       at System.Configuration.LocalFileSettingsProvider.SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection values)
       at System.Configuration.SettingsBase.SaveCore()
       at System.Configuration.SettingsBase.Save()
       at System.Configuration.ApplicationSettingsBase.Save()
       at ETSquare.MainWindow.Eingangsart_Changed(Object sender, RoutedPropertyChangedEventArgs`1 e)
  InnerException: System.Configuration.ConfigurationErrorsException
       BareMessage=A configuration file cannot be created for the requested Configuration object.
       Line=0
       Message=A configuration file cannot be created for the requested Configuration object.
       Source=System.Configuration
       StackTrace:
            at System.Configuration.MgmtConfigurationRecord.SaveAs(String filename, ConfigurationSaveMode saveMode, Boolean forceUpdateAll)
            at System.Configuration.Configuration.SaveAsImpl(String filename, ConfigurationSaveMode saveMode, Boolean forceSaveAll)
            at System.Configuration.ClientSettingsStore.WriteSettings(String sectionName, Boolean isRoaming, IDictionary newSettings)
       InnerException:


This problem happens on every Machine. The environment is Windows XP 32-bit andWindows 7 64bit

The application is a WPF-Browser-Application (xbap).

If I put a 'Properties.Settings.Default.Upgrade()' before the save-command,

Code:

C#
Properties.Settings.Default.UserProp = "MyUserValue";
  Properties.Settings.Default.Upgrade();
  Properties.Settings.Default.Save();


I get

System.ArgumentNullException was caught
  Message=Value cannot be null.
Parameter name: path
  ParamName=path
  Source=mscorlib
  StackTrace:
       at System.IO.Directory.GetParent(String path)
       at System.Configuration.LocalFileSettingsProvider.GetPreviousConfigFileName(Boolean isRoaming)
       at System.Configuration.LocalFileSettingsProvider.Upgrade(SettingsContext context, SettingsPropertyCollection properties, Boolean isRoaming)
       at System.Configuration.LocalFileSettingsProvider.Upgrade(SettingsContext context, SettingsPropertyCollection properties)
       at System.Configuration.ApplicationSettingsBase.Upgrade()
       at ETSquare.MainWindow.Eingangsart_Changed(Object sender, RoutedPropertyChangedEventArgs`1 e)
  InnerException:

Any idea please. Thanks in advance.
Posted
Comments
Richard MacCutchan 9-Dec-15 15:35pm    
It sounds like you do not have a settings file in existence. Add one to your project first and try again.
xszaboj 9-Dec-15 18:48pm    
look like config file is missing. try read this thread might help: https://social.msdn.microsoft.com/Forums/vstudio/en-US/ddeaca86-a093-4997-82c9-01bc0c630138/propertiessettingsdefaultsave-does-not-save-a-userconfig-file?forum=csharpgeneral

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900