1

I am truly confused. Everytime I try to install my windows service, using InstallUtil.exe, I get the error below:

Exception occurred while initializing the installation: System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize.

The general advice is:

"inside the "configuration" element, the first child must be the "configSections"

In order to just try to get past the error message, I completely stripped my App.config down to:

<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    </configuration>

But the same error persists. It's like the installer is completely ignoring the newly empty App.config file, and I am thoroughly confused as to how to overcome this.

This is attempted to be installed on a Windows Server 2008 R2 - code written in C# 4.0. Can anyone recommend a direction to look? TIA

leppie
  • 115,091
  • 17
  • 196
  • 297
Jeff Borden
  • 1,369
  • 1
  • 19
  • 30
  • Based on the error you would say that you should have left `configSections` in the file – rene Feb 27 '14 at 21:54
  • 2
    Maybe this question is duplicated! Check this ;) http://stackoverflow.com/questions/1991779/configuration-system-failed-to-initialize-windows-service-net – Oscar Bralo Feb 27 '14 at 21:55
  • Or have a look here http://stackoverflow.com/questions/6436157/configuration-system-failed-to-initialize/6472696#6472696 – rene Feb 27 '14 at 21:56
  • 2
    @OscarBralo you brilliant man you. I had read through all SO posts about this, but missed this one. Tweaked the machine.config file the other day, and after removing the tweak, it now works. <3 – Jeff Borden Feb 27 '14 at 22:09
  • 2
    I am glad to help Jeff! – Oscar Bralo Feb 27 '14 at 22:12
  • @OscarBralo your comment saved me. I remembered that we installed the DB2 i-series data provider, which will corrupt the machine.config DBProviderFactories tag. Remember to fix machine.config in both Framework folders (Framework and Framework64) when appilcable. – Tom Regan Apr 03 '15 at 21:34

1 Answers1

0

I am not sure if i missed some settings or so. But break pointing helped me realise that configuration manager was not fetching the config settings despite following the native style or the recommended patterns.

then i hit this msdn reference

the pattern allowed my service code to fetch values from the config. sticking to this for time constraints. need to explore why the native patters is problematic.

modify the code to follow the below style if possible

System.Configuration.AppSettingsReader reader = new System.Configuration.AppSettingsReader();

LOGFOLDER = reader.GetValue("LogFolder", typeof(string)).ToString();

and the app.config should be like:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key = "LogFolder" value = "D:\Projects\Logs\" />
    </appSettings>
</configuration>

and remember to add System.Configuration in references!

hope this helps.

r.sumesh
  • 313
  • 1
  • 3
  • 13