Search This Blog

Friday, November 22, 2013

How to fix Configuration system failed to initialize

Configuration system failed to initialize- Issue in .NET

Problem : 

I was working on a console application which will work as a Task Scheduler on the server, so I created a console application in Visual Studio 2012, so the project was created with Target Framework as v4.5, but the problem with that was, neither our QA server or Production server for that app had Framework v4.5 installed on them. So what I did was, I went to the project properties and changed the Target Framework to 4.0 instead of 4.5 and tried to run on Debug, thats it, I keep getting the error whenever the application was trying to read configuration values using ConfigurationManager.AppSettings and the error reads as below

"Configuration system failed to initialize".

Solution : 

Like most of us, I copied the exception details and googled it and this is what I got as a probable resolution from Stack overflow.



make sure that your config file (web.config if web, or app.config if windows) in your project starts as:
<?xml version="1.0"?>
<configuration>
   <configSections>
      <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="yourProjectName.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>

The above answer and more such similar answers on the internet points to the configSettings section & has been marked as an answer by most people so I guess this has resolved their issues but not in my case. It still gave me the errors. So this is what I did to get it resolved.

If you have an already running Console Application like me lets say in v4.5, then 
1. If that application is open in visual studio make sure its running in the current version, just check-in your changes to source control and close the studio.
2. Open the *.csproject file on notepad and change the targetFramework from 4.5 to 4.0 like this 
"<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>" and save the file.
3. Open the project now on visual studio and go to App.config file and make the change in the file under element startup and make .NETFramework, Version=v4.0 like below

<startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
    </startup>

Now if you run your application, it should run just fine, atleast in my case.


No comments:

Post a Comment