none
How to handle ConfigurationErrorsExceptions?

    Question

  • Hi.

    In my application I allow users to send me unhandled exceptions as error reports, so that I can see what is going wrong.
    I'm currently looking into ConfigurationErrorsExceptions. There are over a hundred reports of them, these are the types I get:

    Failed to save settings: The configuration file has been changed by another program. 

    Failed to save settings: Unable to save config to file 'C:\Documents and Settings\NAME\Local Settings\Application Data\Company\myapp.exe_Url_ibigjzvkuse2hwwr14gi0vqvafl5ifm4\4.0.15.277\user.config'.
    Most frequent one! Stacktrace below.

    Code Snippet


    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 CDBurnerXP_Pro.My.MyApplication.OnInitialize(ReadOnlyCollection`1 commandLineArgs)
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()

    Inner exception:
    System.Configuration.ConfigurationErrorsException: Unable to save config to file 'C:\...\user.config'.
    at System.Configuration.Internal.WriteFileContext.ReplaceFile(String Source, String Target)
    at System.Configuration.Internal.WriteFileContext.Complete(String filename, Boolean success)
    at System.Configuration.Internal.InternalConfigHost.StaticWriteCompleted(String streamName, Boolean success, Object writeContext, Boolean assertPermissions)
    at System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.WriteCompleted(String streamName, Boolean success, Object writeContext, Boolean assertPermissions)
    at System.Configuration.Internal.DelegatingConfigHost.WriteCompleted(String streamName, Boolean success, Object writeContext, Boolean assertPermissions)
    at System.Configuration.ClientSettingsStore.ClientSettingsConfigurationHost.WriteCompleted(String streamName, Boolean success, Object writeContext)
    at System.Configuration.UpdateConfigHost.WriteCompleted(String streamName, Boolean success, Object writeContext)
    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.Configuration.Save()
    at System.Configuration.ClientSettingsStore.WriteSettings(String sectionName, Boolean isRoaming, IDictionary newSettings)


    An error occurred loading a configuration file: The process cannot access the file 'C:\Documents and Settings\Administrator\Local Settings\Application Data\Company\myapp.exe_Url_nfryvllqiqb1hla4nzefaejvhwflc2o0\4.0.15.277\user.config' because it is being used by another process. (C:\Documents and Settings\Administrator\Local Settings\Application Data\Company\myapp.exe_Url_nfryvllqiqb1hla4nzefaejvhwflc2o0\4.0.15.277\user.config)

    An error occurred creating the configuration section handler for userSettings/Namespace.My.MySettings: Object reference not set to an instance of an object. (C:\Documents and Settings\NAME\Local Settings\Application Data\Company\myapp.exe_Url_nfryvllqiqb1hla4nzefaejvhwflc2o0\4.0.15.277\user.config line 5)

    Data at the root level is invalid. Line 1, position 1. (C:\Documents and Settings\NAME\Local Settings\Application Data\Company\myapp.exe_Url_nfryvllqiqb1hla4nzefaejvhwflc2o0\4.0.13.220\user.config line 1)

    An error occurred creating the configuration section handler for userSettings/Namespace.My.MySettings: Entry point was not found. (C:\Documents and Settings\NAME\Local Settings\Application Data\Company\myapp.exe_Url_nfryvllqiqb1hla4nzefaejvhwflc2o0\4.0.22.370\user.config line 5)

    An error occurred creating the configuration section handler for userSettings/Namespace.My.MySettings: Invalid syntax on line 1. (C:\Documents and Settings\NAME\Local Settings\Application Data\Company\myapp.exe_Url_nfryvllqiqb1hla4nzefaejvhwflc2o0\4.0.22.370\user.config line 5)


    I'm only using the default methods (My.Settings.Save() in VB.NET). So far it does not seem to relate to the used OS. Also, it works for me and most of the users.
    Can anyone suggest how to handle those exceptions? I can also provide a full stacktrace for all exceptions if that helps.
    Thanks.
    Monday, April 07, 2008 4:27 PM

All replies

  • Hi,

     

    How many instances of your application are running? Most likely this sittuation occurs due to concurrency between two or more instances of your application.

     

    Tuesday, April 08, 2008 6:34 AM
  • There is just one, unfortunately.
    Tuesday, April 08, 2008 7:53 AM
  • In response to:

     flöle wrote:

    How to handle ConfigurationErrorsExceptions? has replies but is not marked as answered. Please visit your post and let us know if the reply answers your question.


    No, the reply did not answer my question. Weired notifications here...
    Thursday, April 10, 2008 4:10 PM
  • i have the same situation. And i don't want to use .Net settings now. Unfortunately, the same problem i have with code compilation, xmlserializers and another. I'm sorry Sad

    Tuesday, April 15, 2008 11:21 AM
  • Hi, I found this post by googling. We experience exactly the same problem (I mean the "because it is being used by another process" one), but I can't find a good solution from MS. I hope some expert can say something more about this.

    A customer told us how he got this exception: he opened multiple instances of the same application (which is legal) in Win XP. On the taskbar the programs then grouped under one taskbar button. Then he clicked right and selected 'Close group', to close all instances of the program at once.

    Then this exception occurs.

    Could it be that by closing multiple instances this way, the instances are not closed in sequence, but in parallel?

    The problem does not occur always - but often if you use Close Group.

    Wednesday, October 05, 2011 9:32 AM
  • Hi, 

    I found a solution for this.

    I had the same issue, i realized that I have failed to add 'allowExeDefinition="MachineToLocalUser"' to the section in app.config file

    and this soved the issue for me.

    Thursday, August 29, 2013 9:18 AM