Configuration system failed to initialize - Help Please

When i try to run my app I get this exception "Configuration system failed to initialize"
I recently added a datascource to the app and am assuming that something has gone wrong there but it was all working ok and then this error just started.
I assume it's a problem with my appconfig file which i'll post here I cant see anything wrong with it but.!!
I've tried deleting the ConnectionString Section but nothing helps and i cant run my app at all!

Heeeeeelp!!

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Bank.My.MySettings.AustralianConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot;C:\Documents and Settings\Mike\Desktop\Bank dev\Current Accounts\Australian.mdb&quot;"
providerName="System.Data.OleDb" />
</connectionStrings>
<appsettings>
<add key="appname" value="Bank.exe" />
</appsettings>
</configuration>

[1074 byte] By [Mikepy] at [2008-1-10]
# 1
With it being that small, why not just delete the file and let a new one be generated?
BTW you can change &quot; to a single quote: ' , unless that's the way the config is being saved even with a single quote as part of your originial string.
Randy
RandyCragin at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
I got this error earlier this evening when I changed the settings available in My.Settings - what I found in my case was that one of the changes I had made had added a StringCollection and it needed a try-catch block to create a new instance the first time around if it didn't exist.

That, plus I had corrupted the user.config file.... when I deleted that it wrote a new one and started working fine.

Good luck!

Mike

MickRivers. at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
Glad to hear that you solved your problem. Out of curiosity - did you try the Synchronize button in the settings designer? It will try & hunt down and delete any user.config files that may be out of sync/broken...

Best regards,
Johan Stenberg

MSFTJohanStenberg at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4
Thanks all.
I deleted the config file and it worked ok but i still dont know how it got stuffed up as i never touched it!

Still it's ok now

Thanks

Mikepy at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
I'm getting the same error message, but I can't get it to go away no matter what I do. All I did was add a simple application-level setting, and now the settings refuse to work. I've tried deleting all auto-generated files in the project and letting them regenerate. I've tried removing all the settings and re-adding them. I don't have any user-level preferences in this project, so the Synchronize button doesn't help. I've even tried setting up a new project with the same old files. Nothing has worked.

I can force the project to compile it by manually editing the Settings.Designer.vb file and forcing the desired settings to return, but this rather defeats the purpose. E.g., everything in the following was autogenerated except the apostrophe before the commented line and the line that precedes it:

<Global.System.Configuration.ApplicationScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute("False")> _
Public ReadOnly Property usingTestDB() As Boolean
Get
Return False
'Return CType(Me("usingTestDB"),Boolean)
End Get
End Property

If I leave the code as is, then when execution gets to the Return Ctype etc. line it throws an exception with error message ("Configuration system failed to initialize".). Any other ideas that aren't in this thread already?

albedo20 at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6

It sounds like the .config file is broken at some level (most likely local user or roaming user). To locate the files, you can add the following to the constructor of your settings class (or in the settings property get:er that you modified to always return false).

Dim exeConfig As System.Configuration.Configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None)

Debug.WriteLine(exeConfig.FilePath)

Dim localConfig As System.Configuration.Configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal)

Debug.WriteLine(localConfig.FilePath)

Dim roamingConfig As System.Configuration.Configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoaming)

Debug.WriteLine(roamingConfig.FilePath)

This will print the location of the exe, local user and roaming user config files. Take a look in those files (if they exist) and look for any stray user scoped setting (you say that you don't have any user scoped settings, so unless any of the assemblies that you reference have user scoped settings, there shouldn't be any).

Let me know if this helps,
Johan Stenberg

MSFTJohanStenberg at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 7
Thanks, it worked. Somehow a user.config file from an old incarnation of the project had persisted and was intermittently wreaking havoc. Odd that the Synchronize button in the Settings Designer didn't find it, though.
albedo20 at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 8

It's good to hear that you managed to solve the problem.

The synchronize button in the settings designer tries as hard as it can to find all the files involved, but there are some things that it can't determine. In particular, two things that tend to make it confused is if you have click-once deployed or strong-named your executable. This is one area that we are looking to improve in the next version of Visual Studio.

Best regards,
Johan Stenberg

MSFTJohanStenberg at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 9
Hi

The error is because you write appsettings and it is appSettings. The config file is case sensitive, i hope that helps.

Pablo

ElToby at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 10

I'm getting a similar error; however, mine occurs whenever I add a reference to the System.configuration file in the references section of my project.

I'm trying to write to an app.config file using ConfigurationManager.AppSettings.Add and I may just not be doing things right, but the reference to the already existing non-tampered with setting seems to no longer exist after I added the System.configuration reference.

Anyone have any idea about this?

Justin0509 at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 11

This was most helpful. I had the same problem after trying to clean up a bunch of duplicate connection strings the Visual Studio had created that pointed to the same place. The synchronize button fixed everything. I had even tried deleting the entire DataSet and recreating that.

Thanks,

Ken

KenCulp at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 12

I have the same problem, but I am not sure why I am getting it. I tried displaying the exe Config, localConfig, roamingConfig and it displays nothing. I please do note that I am getting this error when I am trying to call the serviced component (.Net 2.0 code) method in ASP. Any ideas how I can fix this.

Thanks,

Kumarp

Kumarp at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 13

I was getting a similar error "Configuration system failed to initialize"

When I checked the error details it asked me to put <configSections> as the first section of <configuration> in app.config. I had put <appSettings> as the first element. I moved <configSections> on top and it worked fine for me.

Hope this helps.

Mohammed

Aeraf at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 14
Hi mohammed, thank you so much for ur great idea and stopping me to waste my time to solve this problem.
antonyleo at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...