I installed a Windows serivce that fetches has to fetch some strings from the App.Config file by the following method in OnStart – ConfigurationManager.AppSettings["stringName"];
Inside the App.Config, I also have a source defined for the log file which I use to write to my log file.
However, as I successfully install my service and try to start it from Serivce Control Explorer inside My Computer -> Manage - > Device Manager, I get a message saying
The service on the local computer and then stopped. Some services stop automatically if not used by toher applications
Inside the Windows Event Viewer, I get the following error detail (perhaps there is an exception thrown while starting the service)
Here’s the error detail for the same:
Service cannot be started. System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section add. (C:\Program Files (x86)\Default Company Name\ServiceSetup\ServiceChecker.exe.Config line 3)
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
--- End of inner exception stack trace ---
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Dia...
The above detail shows error detail related to .exe.config file of the service. I have tried uninstalling and reinstalling the service and the installation Account for the serivce is set as Local system which has broad system previliges.
my App.Config in the project:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="UtilName" value="sample.exe"/>
<add key="App1" value="MyApp"/>
<add key="App1E" value="MyApp.exe"/>
<add key="App2" value="MyApp2"/>
<add key="App2E" value="MyApp2.exe" />
<add key="AppDirectory" value="Company\MyProject" />
<add key="CMDArgs" value="\start"/>
</appSettings>
<system.diagnostics>
<sources>
<source name="ServiceTrace" switchName="ServiceTraceSwitch" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="ServiceLog" type="System.Diagnostics.TextWriterTraceListener" initializeData="servicetrace.log"/>
</listeners>
</source>
</sources>
<switches>
<add name="ServiceTraceSwitch" value="Information" />
</switches>
<trace autoflush="true" indentsize="4"></trace>
</system.diagnostics>
</configuration>
Seems that your app.config (or .exe.config) contains an unrecognized section. The error message usually says something like
so i assume that you just added your config values without the needed parent element. The element has to be added as a child element of the section. Make sure it looks something like this: