记一次windows服务开发中遇到的问题
最近在研究windows service和quartz.net,所以迅速在园子大神那里扒了一个demo,运行,安装一切顺利。
但在在App.config配置中增加了数据库连接字符串配置后,服务安装后无法启动。把这个配置去掉,连接串直接写入代码则成功启动成功。接着试了几次都是无功而返。找了各种原因:更换.net framework版本、更换服务器.....

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="xxxx" value="数据库连接串"/>
</appSettings>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1213">
<arg key="configType" value="FILE-WATCH" />
<arg key="configFile" value="~/Conf/log4net.config" />
<arg key="level" value="INFO" />
</factoryAdapter>
</logging>
</common>
为什么增加了<appSettings>配置就会报错呢?这个问题一直困扰了我整整2天时间,真是郁闷之极。
最后在服务器错误日志中发现无法启动的原因,确实是由于config配置问题,但具体是什么原因还是无解。
应用程序: QuartzNETWinService.exe
Framework 版本: v4.0.30319
说明: 由于未经处理的异常,进程终止。
异常信息: System.Configuration.ConfigurationErrorsException
在 System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean)
在 System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(System.Configuration.ConfigurationSchemaErrors)
在 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.GetSection(System.String)
在 Common.Logging.LogManager+<>c__DisplayClass6.<BuildLoggerFactoryAdapter>b__3()
在 Common.Logging.Configuration.ArgUtils+<>c__DisplayClass5.<Guard>b__4()
在 Common.Logging.Configuration.ArgUtils.Guard[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](Function`<Int32>, System.String, System.Object[]) 异常信息: Common.Logging.ConfigurationException
在 Common.Logging.Configuration.ArgUtils.Guard[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](Function`<Int32>, System.String, System.Object[])
在 Common.Logging.LogManager.BuildLoggerFactoryAdapter()
在 Common.Logging.LogManager.get_Adapter()
在 Common.Logging.LogManager.GetLogger(System.Type)
在 Wlitsoft.ProjectSample.QuartzNETWinService.MainService..ctor()
在 Wlitsoft.ProjectSample.QuartzNETWinService.Program.Main()
异常信息: Common.Logging.ConfigurationException?????
难道和这个组件有关系?于是百度,关键词为“Common.Logging config”,果然发现一篇文章
https://stackoverflow.com/questions/6779711/common-logging-config-exception
在回复中有这么条信息
If this element is in a configuration file, it must be the first child element of the <configuration> element
Whoa! Indeed, remove that and it works. extra points if you state 'why'. – Jahmic Jul '11 at 17:18 I believe it's because of how the configuration schema is validated or loaded. – Klinger Jul 21 ' at :
nice one! This answer is still valid for VS2012/.Net 4.5, Common.Logging 2.1., Common.Logging.Log4Net 2.0. and log4net 1.2. – Lin-Art Oct '12 at 11:01 From the docs on the configSections element: "If this element is in a configuration file, it must be the first child element of the <configuration> element." – stuartd Sep '14 at 13:00
what a tricky change, took me a while to find out! – Allen Jul '15 at 13:58
而且还有一个指向微软官方文档,https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-1.1/aa903350(v=vs.71),终于找到了问题的症结所在!!!!
<configSections>元素一定要作为<configuration>中的第一个元素!!!于是把<appSettings>移到了configSections节点的下方,问题解决!
是微软给我们挖的坑,还是自己功力太潜了,不管怎么样折腾2天时间终于把问题解决了。
记一次windows服务开发中遇到的问题的更多相关文章
- C# Windows服务开发从入门到精通
一.课程介绍 大家都知道如果想要程序一直运行在windows服务器上,最好是把程序写成windows服务程序:这样程序会随着系统的自动启动而启动,自动关闭而关闭,不需要用户直接登录,直接开机就可以启动 ...
- ASP.NET Core Windows服务开发技术实战演练
一.课程介绍 人生苦短,我用.NET Core!大家都知道如果想要程序一直运行在Windows服务器上,最好是把程序写成Windows服务程序:这样程序会随着系统的自动启动而启动,自动关闭而关闭,不需 ...
- Java生鲜电商平台-SpringCloud微服务开发中的数据架构设计实战精讲
Java生鲜电商平台-SpringCloud微服务开发中的数据架构设计实战精讲 Java生鲜电商平台: 微服务是当前非常流行的技术框架,通过服务的小型化.原子化以及分布式架构的弹性伸缩和高可用性, ...
- Topshelf 一个简化Windows服务开发的宿主服务框架
Topshelf是 基于.net框架开发的宿主服务框架.该框架简化了服务的创建,开发人员只需要使用 Topshelf编写一个控制台程序,就能安装为Windows服务.之所以这样原因非常简单:调试一个控 ...
- .NET Windows服务开发流程
前段时间做一个数据迁移项目,刚开始用B/S架构做的项目,但B/S要寄存在IIs中,而IIs又不稳定因素,如果重启IIs就要打开页面才能运行项目.有不便之处,就改用Windows服务实现.这篇就总结下, ...
- Windows应用开发中程序窗口中的各种图标尺寸规划
为了让你的图标在各个视图模式下都能有合适的尺寸,需要制作4种尺寸16x16.32x32.48x48.256x256 在Windows系统中,几乎所有窗口都是ListView,其中的图标都按照指定的尺寸 ...
- Windows内核开发中如何区分文件对象究竟是文件还是文件夹?
今天有同行问了一个问题,Windows文件过滤驱动里的如何去区分一个对象是文件还是文件夹?我花了1小时左右翻阅了一些微软的文档以及以前的遗留代码,发现在WDK的帮助文档中是这么定义的: FILE_OB ...
- windows游戏开发中一个关于Visual Studio的编译链接成功,输出窗口却显示线程已退出。无法运行项目的问题
可能是显卡驱动程序版本太高了,退回到以前的版本就ok了. 第一次遇见这个问题可把我给整疯了!! 后来又遇到一次,参考之前的解决方法,很快就搞定了!! 可见,经验可是很重要的一个东西啊.
- WindowsService(Windows服务)开发步骤附Demo
1.打开VS,新建项目,选择Windows服务,然后设置目录及项目名称后点击确定. 2.展开Service1服务文件,编写service1.cs类文件,不是Service1[设计].然后修改OnSta ...
随机推荐
- 3分钟搞明白信用评分卡模型&模型验证
信用评分卡模型在国外是一种成熟的预测方法,尤其在信用风险评估以及金融风险控制领域更是得到了比较广泛的使用,其原理是将模型变量WOE编码方式离散化之后运用logistic回归模型进行的一种二分类变量的广 ...
- ElasticSearch 5.0及head插件安装
一.elasticsearch安装配置 1.官网下载源码包 https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.0 ...
- CentOS 7.2编译安装Tengine
Tengine官网上有个非常简单的教程,中间并未涉及到一些常用的设置,所以仅供参考.一下午为本人的安装步骤及过程. 配置firewalld,iptables,关闭SELINUX 1.安装必要的编译环境 ...
- 小米Pro 安装苹果系统
参考 http://www.miui.com/thread-11363672-1-1.html http://www.miui.com/thread-7601066-1-1.html https:// ...
- ES容易忽视的集群配置
一 前言 目前生产系统由Solr转ES了,在这边就记录下在使用过程中容易忽视的配置吧,其实我也是才用,如果有什么错误的地方,多指正. 二.配置 1.ES的段合并是限速设置 默认是20MB/s ,如果是 ...
- Python3字典
- [译] 理解 LSTM(Long Short-Term Memory, LSTM) 网络
本文译自 Christopher Olah 的博文 Recurrent Neural Networks 人类并不是每时每刻都从一片空白的大脑开始他们的思考.在你阅读这篇文章时候,你都是基于自己已经拥有 ...
- netty 粘包的解决策略
粘包问题的解决策略 由于底层的 TCP 无法理解上层业务数据,所以在底层是无法保证数据包不被拆分和重组的 , 这个问题只能通过上层的应用协议栈设计来解决,根据业界主流的协议的解决方案, 可以 ...
- Webpack+Vue+ES6 前端组件化开发mobile-multi-page应用实战总结和踩坑
本文版权归博客园和作者吴双本人共同所有 转载和爬虫请注明原文地址 www.cnblogs.com/tdws 一.写在前面 项目上线有一段时间了,一个基于webpack+vue+ES6的手机端多页面应用 ...
- [转帖]Loading Data into HAWQ
Loading Data into HAWQ Leave a reply Loading data into the database is required to start using it bu ...