[ACCEPTED]-.NET 3.5 - Configuration system failed to initialize exception-app-config
I had some user settings, then removed all 13 of them and started seeing this exception 12 - but only when running the app without 11 debugging. It worked fine when debugging 10 the app. The reason is that user-level settings 9 are "cached" in the Local Application Data 8 folder, and in fact are not read from the 7 MYAPP.exe.config. So what I did was go to 6 C:\Users\MYUSERNAME\AppData\Local\MYCOMPANY\MYAPP.exe_Url_longnastyhash9982749827349879\1.0.0.0\user.config 5 (this is on Win7, the path depends on OS) and 4 removed that folder (with the long hash) altogether. The 3 exception went away. BTW, depending on how 2 your settings are setup this user.config 1 file may be under \AppData\Local or \AppData\Roaming.
Try checking that the app.config (myapp.exe.config 2 once deployed) file exists and has at the 1 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>
I get this error when I write my App.Config 3 (stupidly) as below.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!--List of XMLFiles Begins -->
<add key="ConfigFileEnvironment" value="C:\Program Files\MyProduct\Config\Environment.xml" />
<!--List of XMLFiles Ends -->
</configuration>
Notice, that there 2 is no appSettings? I used to do this mistake 1 regularly...
I started seeing this message when I removed 3 all userSettings. I was able to fix it 2 by adding a single userSetting back into 1 the settings files.
Clean Solution Delete all currently existing 5 settings files as well as app.config Close 4 VS Manually go in and clear out the bin 3 folder and the obj folder of your project Restart 2 PC Re-add the "Application Configuration 1 File"
I had some garbage in my machine.config 4 that was causing this error. Look for the 3 exception stack trace and see if you have 2 the same problem. It was essentially malformed 1 XML.
I had a this problem today and found that 7 I'd accidentally (not to mention erroneously) added 6 a second custom configuration section to 5 my App.config. Once I removed the errant 4 addition, I was able to continue running 3 my application without problems.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="ABCConfig" type="ABC.Configuration.ABCConfigurationSection, ABC"/>
<!-- Other custom section definitions -->
</configSections>
<connectionStrings>
<!-- Connection strings go here -->
</connectionStrings>
<!-- Configure ABC -->
<ABCConfig CustomA="blah" CustomB="stuff" />
<!-- Other custom sections -->
<!-- Errant addition to Configure ABC which causes the problem - SHOULD NOT BE HERE -->
<ABCConfig CustomA="blah" CustomB="stuff" />
</configuration>
Removing 2 the second ABCConfig section resolved my 1 problem. Hope this helps!
Probably the problem is that your config 3 file doesn't comply with its schema. For 2 example, this issue can be recreated by 1 duplication the ConnectionStrings section.
I had this problem because I changed one 10 application setting scope (from 'application' to 9 user'). As I couldn't find a solution to 8 resolve my problem, I decided to delete 7 the settings file into the solution explorer. After 6 that, I opened the properties, in the tab 5 'settings', I clicked where it was proposed 4 to create the settings file. And a new settings 3 file has been created with the values I 2 defined into the previous settings file. I 1 rebuilt my project and it worked well.
The startup tag did the trick for me on 3 VS Pro 2013 version 12.021005.1 with .Net 2 4.5.51650 for console application (i.e. app.config 1 file)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
...
</connectionStrings>
</configuration>
Just posting here as I found my fix to the 6 issue but don't see it listed here....
I 5 added an appSettings tag under the main 4 configuration node and when I ran it I got 3 the same error as OP. What fixed it was 2 making sure the configSections node preceeded 1 my appSettings node.
I got this error when a .NET 4.x build of 14 my app has already generated the common 13 user.config
file under the AppData
folder, and then I launched 12 the .NET 3.5 version.
And though deleting 11 the user.config
under %APPDATA%\Local\<Company>\<AppName>_StrongName_*\<Version>
as per @beluga's suggestion 10 solves the issue, the settings will also 9 be lost, and it can be quite frustrating 8 for a user to dig up the file to delete 7 if this happens.
But actually there is a 6 way even for a .NET 3.5 build to be able 5 to use the config file.
The culprit is the 4 sectionGroup
element where the UserSettingsGroup
type uses the .NET 4.x 3 assembly identity:
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
To handle this from the 2 app you need to apply some custom assembly 1 resolution logic:
// somewhere in your application startup:
AppDomain.CurrentDomain.AssemblyResolve += HandleAssemblyResolve;
where the event handler:
private static Assembly HandleAssemblyResolve(object sender, ResolveEventArgs args)
{
// System.dll, any version
if (args.Name.StartsWith("System, Version=", StringComparison.Ordinal))
return typeof(UserSettingsGroup).Assembly;
// for any other assembly letting the default logic take over
return null;
}
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.