记一次windows服务无法安装问题

windows服务开发完成以后,开始安装,提示服务已停止,即无法安装,查看事件查看器,有如下报错:

应用程序: xxx.exe
Framework 版本: v4.0.30319
说明: 由于未经处理的异常,进程终止。
异常信息: System.Configuration.ConfigurationErrorsException
在 System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean)
在 System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(System.Configuration.ConfigurationSchemaErrors)
在 System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
在 System.Configuration.ClientConfigurationSystem.EnsureInit(System.String)

异常信息: System.Configuration.ConfigurationErrorsException
在 System.Configuration.ClientConfigurationSystem.EnsureInit(System.String)
在 System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(System.String)
在 System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(System.String)
在 System.Configuration.ConfigurationManager.get_AppSettings()
在 xxx..cctor()

异常信息: System.TypeInitializationException
在 xxx.Main(System.String[])

解决方法:

<configSections>元素一定要作为<configuration>中的第一个元素!

微软官网文档:https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-1.1/aa903350(v=vs.71)

<configSections> Element

If this element is in a configuration file, it must be the first child element of the <configuration> element.

原文地址:https://www.cnblogs.com/zhangtingzu/p/12407839.html