Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
894 views
in Technique[技术] by (71.8m points)

configuration - Windows Service Config File C#

I've developed a windows service application using Visual Studio 2008 / C#.

I have an app.config file in the project. When installed, the app.exe.config file appears beside the executable but it appears not to be reading the values from it when I try to access them through ConfigurationManager.AppSettings.

Has it copied the config file elsewhere or is there some other problem I don't know about?

Thanks in advance,

Martin.

Edit: The config file name is infact my_exe_file_name.exe.config, it looks like:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>

    <add key="RuntimeFrequency" value="3" />

  </appSettings>
</configuration>

and I am trying to read via:

ConfigurationManager.AppSettings["RuntimeFrequency"]

The debug value I continually see is '1' and not '3'. Am I doing something wrong here?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I located the error and it was related to file permissions. After installing the service, my local user account didn't have access to modify the app.exe.config file.

The tool I was using to edit was not informing me it was being denied access to save the file - that's notepad++ if anyone is interested - so I couldn't see that it wasn't saving over the old config file.

Solved now, thanks everyone.

Martin.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...