c# error:Unrecognized configuration section userSettings - stop program reading user.config?
Asked Answered
S

5

25

In my c# form application (created in VS2010, using .NET 4.0) I use an application setting to store an output path.

Previously this setting was configured with a user scope, but I had to change its scope to application.

After doing this I now get an Unrecognized configuration section userSettings error on start up of the form (note the program has been executed before with the setting's scope set to user):

InnerException: System.Configuration.ConfigurationErrorsException
   Message=Unrecognized configuration section userSettings. (C:\Documents and Settings\Administrator\Local Settings\Application Data\CallCenterForm\CallCenterForm.vshost.exe_StrongName_bplf30wziudnpq0knzaacfuyomd5rv45\1.0.0.0\user.config line 3)
   Source=System.Configuration
   BareMessage=Unrecognized configuration section userSettings.
   Filename=C:\Documents and Settings\Administrator\Local Settings\Application Data\CallCenterForm\CallCenterForm.vshost.exe_StrongName_bplf30wziudnpq0knzaacfuyomd5rv45\1.0.0.0\user.config

So after doing some browsing this seems to be caused by the old user.config file still existing on the system, causing the program to read it and throw an error (I'm not sure what the actual underlying problem is). I can also confirm that when I remove the file the problem goes away.

Which brings me to my question, is there a way I can change the program so that it won't read the old user.config file, because deleting it manually isn't ideal as the program is already in production on multiple systems.

Apologies if this has been covered, but I couldn't find an answer.

In case it's helpful here's the contents of my App.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="CallCenterForm.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>
  <applicationSettings>
    <CallCenterForm.Properties.Settings>
      <setting name="saved_output_dir" serializeAs="String">
        <value>c:\</value>
      </setting>
    </CallCenterForm.Properties.Settings>
  </applicationSettings>
</configuration>
Spitler answered 8/11, 2012 at 22:22 Comment(1)
Almost the same issue, maybe it can be helpful hereDecaffeinate
L
50

I ran into this error myself today. The solution was to go into the Assembly Information dialogue of the project's properties and advance the assembly and file version info (ex. 1.0.0.0 to 1.0.1.0), save the changes, and rebuild the application. This will cause the compiler to reevaluate the configuration and cause the application to refrain from creating and reading a new user.config file corresponding to the new version due to there being no user settings in the new version.

Lackey answered 4/9, 2013 at 9:22 Comment(4)
Thanks, doing this uncovered a deeper problem with the config file.Unintelligent
Thank you! I almost didn't try it seemed so unlikely, but when i tried it, BAM. :D Fixed!Darmstadt
Thank you!!. But do i need to change the version every time i rebuild the application?.Pigtail
This resolution still works in 2024.Prussianism
K
8

How did App.config use to look like when there was user.config as well? I'm guessing you need to still declare <sectionGroup name="userSettings" ... > the way it used to be declared.

Kentonkentucky answered 8/11, 2012 at 22:32 Comment(0)
C
7

You can fix the error by navigating to the current directory where the user settings are being saved for your app. This will be in %system%\users\your_user\AppData\Local\Microsoft\YourApp.vshost.######\version. or Delete the user.config file, clean your solution, and Rebuild All. This should fix the problem.

Cyanine answered 6/2, 2019 at 4:49 Comment(0)
E
2

I had the same issue. I had to clean and rebuild the solution. This solved the issue.

Eldoraeldorado answered 15/9, 2016 at 8:57 Comment(0)
D
0

I have a same the issue and I found a solution:

  1. Remove the Settings.settings file if exists in Project/Properties/Setting.settings and app.config file
  2. Right click on Properties -> add new Settings.settings file again
  3. Double click on Settings.settings file to open
  4. Finally add example value -> Save

The issue is resolved

Devisee answered 16/6, 2021 at 14:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.