Windows服务和ConfigurationManager [英] Windows Service and ConfigurationManager

查看:165
本文介绍了Windows服务和ConfigurationManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我不知道为什么我无法访问我的windows中的app.config文件

服务应用程序。它在win32应用程序中运行良好。我已经用相同的情况测试了

和我的服务,但在我的服务中,通过

configurationmanager进行了通话(

configurationmanager.appsettings [" myName"]。tostring())显示null

引用异常。有什么想法吗?这是我的app.config文件数据

< configuration>

< appSettings>< add key =" myName" value =" Myo Zaw" />< / appSettings>

< / configuration>


再次感谢,

myo zaw

解决方案



" Myo Zaw" <在******** @ hotmail.com>在消息中写道

新闻:Os ************** @ tk2msftngp13.phx.gbl ...

hi,
我不知道为什么我无法访问我的windows
服务应用程序中的app.config文件。它在win32应用程序中运行良好。我已经用相同的情况测试了
和sceniro但是,在我的服务中,通过
configurationmanager调用(
configurationmanager.appsettings [" myName"]。tostring())显示我为null
引用异常。有什么想法吗?这是我的app.config文件数据
< configuration>
< appSettings>< add key =" myName" value =" Myo Zaw" />< / appSettings>
< / configuration>

再次感谢,
myo zaw




确保您的配置文件与您的服务.exe

文件位于同一文件夹中。


Willy。




不,

仍然没有成功。


myo zaw


确保app.config文件的部署名称(在解决方案资源管理器中,应该在项目中显示为b $ b)与构建的EXE程序集名称加上.config相同。


确保您的项目具有对System.Configuration的引用。 dll

(默认不存在)。


否则,你有一个语法错误,但是从你的帖子来看它没有'看起来很像

就是这个问题。


彼得


-

联合创始人,Eggheadcafe.com deve loper门户网站:
http://www.eggheadcafe.com

UnBlog:
http://petesbloggerama.blogspot.com



" Myo Zaw"写道:


不,
仍然没有成功。

myo zaw



hi,
i don''t know why i can''t access to app.config file in my windows
service application. it worked fine in win32 application. i already tested
with the same situation and sceniro but, in my service, the call through
configurationmanager (
configurationmanager.appsettings["myName"].tostring() ) showed me null
reference exception. any idea about that? this is my app.config file data
<configuration>
<appSettings><add key="myName" value="Myo Zaw" /></appSettings>
</configuration>

thanks again,
myo zaw

解决方案


"Myo Zaw" <in********@hotmail.com> wrote in message
news:Os**************@tk2msftngp13.phx.gbl...

hi,
i don''t know why i can''t access to app.config file in my windows
service application. it worked fine in win32 application. i already tested
with the same situation and sceniro but, in my service, the call through
configurationmanager (
configurationmanager.appsettings["myName"].tostring() ) showed me null
reference exception. any idea about that? this is my app.config file data
<configuration>
<appSettings><add key="myName" value="Myo Zaw" /></appSettings>
</configuration>

thanks again,
myo zaw



Make sure your config files resides in the same folder as your Service .exe
file.

Willy.



no,
still didn''t work out.

myo zaw


Make sure that the deployed name of the app.config file (which should be
visible "in your project" in Solution Explorer. turns out to be the same as
the built EXE assembly name plus ".config".

Ensure that your project has a reference to the System.Configuration.dll
(it''s not there by default).

Otherwise, you''ve got a syntax error, but from your post it doesn''t look
like that''s the issue.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Myo Zaw" wrote:


no,
still didn''t work out.

myo zaw



这篇关于Windows服务和ConfigurationManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆