Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET 3.5 - Configuration system failed to initialize exception

In my winform app, I am trying to add a userSetting, although the error is occuring with appSettings too. When the setting is added I get an exeption thrown that says: "Configuration system failed to initialize" with a Inner Exception "Unrecognized configuration section userSetting"

Exception Details:

System.Configuration.ConfigurationErrorsException was unhandled
  Message="Configuration system failed to initialize"
  Source="System.Configuration"
  BareMessage="Configuration system failed to initialize"
  Line=0
  StackTrace:
       at System.Configuration.ConfigurationManager.PrepareConfigSystem()
       at System.Configuration.ConfigurationManager.RefreshSection(String sectionName)
       at System.Configuration.ClientSettingsStore.ReadSettings(String sectionName, Boolean isUserScoped)
       at System.Configuration.LocalFileSettingsProvider.GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
       at System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider provider)
       at System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName)
       at System.Configuration.SettingsBase.get_Item(String propertyName)
       at System.Configuration.ApplicationSettingsBase.GetPropertyValue(String propertyName)
       at System.Configuration.ApplicationSettingsBase.get_Item(String propertyName)
       at Settings.get_ApplicationData() in \Properties\Settings.Designer.cs:line 41
       at Common.Initialize.IsSettingsInitialized() 
       at SurveyClient.Program.Main() 
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Configuration.ConfigurationErrorsException
       Message="Unrecognized configuration section userSettings.
       Source="System.Configuration"
       BareMessage="Unrecognized configuration section userSettings."
       Line=3
       StackTrace:
            at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
            at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
            at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
            at System.Configuration.ClientConfigurationSystem.OnConfigRemoved(Object sender, InternalConfigEventArgs e)
       InnerException: 
like image 998
AdamSane Avatar asked Jan 14 '09 14:01

AdamSane


People also ask

Where is app config file in C#?

In Solution Explorer, right-click the project node, and then select Add > New Item. The Add New Item dialog box appears. Expand Installed > Visual C# Items. In the middle pane, select the Application Configuration File template.

What is configSections in web config?

<configSections> element for <configuration>Contains configuration section and namespace declarations.

What is app config?

The app. config file is an XML file whose goal it is to contain any variable configuration of your application. It is a central place to put: Connection strings to databases. Connection details to external services.


2 Answers

I had some user settings, then removed all of them and started seeing this exception - but only when running the app without debugging. It worked fine when debugging the app. The reason is that user-level settings are "cached" in the Local Application Data folder, and in fact are not read from the MYAPP.exe.config. So what I did was go to C:\Users\MYUSERNAME\AppData\Local\MYCOMPANY\MYAPP.exe_Url_longnastyhash9982749827349879\1.0.0.0\user.config (this is on Win7, the path depends on OS) and removed that folder (with the long hash) altogether. The exception went away. BTW, depending on how your settings are setup this user.config file may be under \AppData\Local or \AppData\Roaming.

like image 77
beluga Avatar answered Oct 24 '22 04:10

beluga


Try checking that the app.config (myapp.exe.config once deployed) file exists and has at the top (possibly with other bits)

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings"
    type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
</sectionGroup>
like image 28
Marc Gravell Avatar answered Oct 24 '22 04:10

Marc Gravell