记一次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 ...
随机推荐
- git reflog
http://www.softwhy.com/article-8573-1.html https://www.cnblogs.com/irocker/p/git-reflog.html https:/ ...
- 目前流行前端几大UI框架
title: "Windows照片查看器-召回大法" categories: windows tags: windows author: LIUREN --- Windows照片查 ...
- 使用Træfɪk(traefik)来加速Qt在线更新
简述 在使用Qt的MaintenanceTool程序进行在线更新的时候遇到一个问题,就是访问download.qt.io实在太慢了,老是失败.所以想使用国内的镜像站来进行更新. 使用Qt的镜像站方法也 ...
- 分析技术和方法论营销理论知识框架,营销方面4P、用户使用行为、STP,管理方面5W2H、逻辑树、金字塔、生命周期
原文:五种分析框架:PEST.5W2H.逻辑树.4P.用户使用行为 最近在一点点的啃<谁说菜鸟不懂得数据分析>,相当慢,相当的费脑力,总之,真正的学习伴随着痛苦:) 最初拿到这本书的时候, ...
- linux内核剖析(八)进程间通信之-管道
管道 管道是一种两个进程间进行单向通信的机制. 因为管道传递数据的单向性,管道又称为半双工管道. 管道的这一特点决定了器使用的局限性.管道是Linux支持的最初Unix IPC形式之一,具有以下特点: ...
- “The subscription does not exist” when a distributor primary replica fails over to a replica that does not use the same agent profile
Symptoms Consider the following scenario: In Microsoft SQL Server 2017, you have a distribution agen ...
- UBANTU zongjie
1.fatal error: openssl/aes.h: No such file or directory 要在Debian.Ubuntu或者其他衍生版上安装OpenSSL: $ sudo apt ...
- SQL递归方式实现省市区县级别查询
数据库脚本 CREATE TABLE [dbo].[Std_Area]( [Id] [int] NOT NULL, [Name] [nvarchar](50) NULL, [ParentId] [in ...
- 磁盘 I/O 优化
磁盘 I/O 优化 1. 性能检测 我们的应用程序通常都需要访问磁盘系统,而磁盘 I/O 通常都很耗时, 要判断 I/O 是否是一个瓶颈,有一些参数指标可以参考. 我们可以压力测试应用程序看系统的 I ...
- Java代码实现文件添加数字签名、验证数字签名
Linux下实现加签.验签 1.使用OpenSSL 生成公钥和密钥: #用 OpenSSL, Linux 上自带,常用命令如下: #生成 RSA 私钥(传统格式的) openssl genrsa -o ...