Click here to Skip to main content
15,888,351 members
Articles / .NET

Fixing “Unrecognized configuration section userSetting” Errors

Rate me:
Please Sign up or sign in to vote.
5.00/5 (7 votes)
1 Mar 2011CPOL3 min read 46.7K   1   2
How to handle the “Unrecognized configuration section userSetting” exception

Though I have not seen the error “Unrecognized configuration section userSetting” as a standalone exception, it has come up a number of times for me and surfaces as the inner exception on a “Configuration system failed to initialize” exception.

If you’re running into this error and following along, I’m currently using Visual Studio 2010, mostly on .NET 4.0, and I program in C#. If you’re using a different environment, some of the file names or UI might be a bit different, so you’ll have to adjust accordingly.

The exception will be raised in Settings.Designer.cs, on the first attempt to read a value from the application’s configuration.

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.

Delete the user.config file, clean your solution, and Rebuild All. This should fix the problem.

If that doesn’t work, you may need to go so far as to shut down Visual Studio, clean out all the %system%\users\your_user\AppData\Local\Microsoft\YourApp directories of any config files, and then follow the above steps.

What’s Happening?

When you first add a setting to the application through the UI, the default is to create a user-scoped setting.

1.png

User settings and Application settings are primarily different on two fronts:

  1. Storage location
  2. Run-time accessibility

User settings are read/write and can be altered at run-time. These are perfect to save things like favorites, window layout, user-specific options, color preferences and the like. These files are stored in a directory created for the application, basically sand-boxed from system-wide access and the only place your app can read/write from for free (elevated privileges aside).

Application settings are read only at run-time, and can only be altered by changing the XML file and re-launching the application, or by some creative XML file management (and then a reload on your configuration data). These files are stored in the app directory in app.config and also contain the default settings for users who have not yet launched the app (these are the settings that will be defaulted in for the new users).

I have hit the “Configuration system failed to initialize” error a couple of times, and it always seems to be the User scope default biting me.

Basically, I create a setting, plug along for a while, then go back to add another setting and realize that I had left it in user scope. I switch the first setting to application scope and keep plugging away. Somewhere between then and the next time the application tries to access that property, the exception is thrown and doesn’t give you much detail at the surface level.

Figuring Out the Files You Need to Delete

I said you can likely delete the user.config files without much regard. Truth is if you’re into testing something settings-related, that can be a real inconvenience.

I will drill into the inner exception to find the problem file; it’s only two deep, so it’s easy to find the path of the file in question if you’re willing to dig.

Trust me folks, your debugger is your best friend.

License

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


Written By
Software Developer (Senior)
Canada Canada
For almost 30 years I have been working with computers, learning a myriad of languages and participating in various computing environments.

Though I have been mentoring other developers for the last decade, I have recently found a strong interest in writing and am learning to translate the fun of in-person teaching to something I can get into article form.

I enjoy following technology trends, new gadgets and trying to guess where innovation will lead us next (I'm kinda holding out for a robot-served utopia, but willing to submit to our future robot leaders).

I am a guy who is passionate about my faith, my family and a cure for Juvenile Diabetes (my son lives with this disease).

Comments and Discussions

 
QuestionThanks!!! Pin
John DMC21-Feb-14 7:02
John DMC21-Feb-14 7:02 
QuestionVery helpful Pin
syed shujaat hussain4-Jul-13 1:27
syed shujaat hussain4-Jul-13 1:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.