473,388 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Windows Service/app.config

I've written a simple service that reads the app.config file on start.

It works fine if I start it from the VS IDE -- F5 then installutil

I then created a package, wherein the content of app.config has "" for the
values. With the idea that my user, can enter the information before
starting the service. However; this doesn't work. I'm very confused.

As a test, I "emptied" the app.config file and rebuilt, then did an
installutil. This recreated the error, however; if I did an installutil /u
changed the app.config file (in the bin) and re-installutil-ed it - it
worked.
I then tried installing the app using the package I created. I then went to
that directory and tried the above (uninstall, edit, reinstall) without
luck.
My purpose in using the app.config file, is to point the service to the
location of a different configuration file (as I need the service to monitor
that file)

I'm quite sure it isn't a problem with my code, but would be happy to post
it if necessary.

Am I right that the app.config file is read once, when the service starts?
Or just when it's installed (which seems pointless)

I've been hunting around google and msdn, but not having any luck.

Thanks
TomB
Nov 16 '05 #1
4 17056
"TomB" <sh*****@hotmailXXX.com> wrote in message
news:OX**************@TK2MSFTNGP09.phx.gbl...
I've written a simple service that reads the app.config file on start.

It works fine if I start it from the VS IDE -- F5 then installutil

I then created a package, wherein the content of app.config has "" for the
values. With the idea that my user, can enter the information before
starting the service. However; this doesn't work. I'm very confused.

As a test, I "emptied" the app.config file and rebuilt, then did an
installutil. This recreated the error, however; if I did an installutil /u changed the app.config file (in the bin) and re-installutil-ed it - it
worked.
I then tried installing the app using the package I created. I then went to that directory and tried the above (uninstall, edit, reinstall) without
luck.
My purpose in using the app.config file, is to point the service to the
location of a different configuration file (as I need the service to monitor that file)

I'm quite sure it isn't a problem with my code, but would be happy to post
it if necessary.

Am I right that the app.config file is read once, when the service starts?
Or just when it's installed (which seems pointless)

I've been hunting around google and msdn, but not having any luck.


Yes, the config file is read at run time, the first time it's accessed, not
when it's installed. Beyond that, I can't help much because it's not clear
what your error is, you say "it doesn't work" but you didn't tell us what
you mean by that. Is an exception being thrown? Are you getting back
unexpected values?
Nov 16 '05 #2
Thanks for the reply, I guess I wasn't clear.

The service doesn't start, and errors out, because the value of my string
(read from app.config) is empty.

I don't have the source code with me, but my string(a file location) is read
from the app.config. I know it's not getting populated because my Error Log
(where I sent any errors) shows FileNotFoundException.

Thanks
TomB
"John Vottero" <Jo**@mvpsi.com> wrote in message
news:un**************@TK2MSFTNGP09.phx.gbl...
"TomB" <sh*****@hotmailXXX.com> wrote in message
news:OX**************@TK2MSFTNGP09.phx.gbl...
I've written a simple service that reads the app.config file on start.

It works fine if I start it from the VS IDE -- F5 then installutil

I then created a package, wherein the content of app.config has "" for the values. With the idea that my user, can enter the information before
starting the service. However; this doesn't work. I'm very confused.

As a test, I "emptied" the app.config file and rebuilt, then did an
installutil. This recreated the error, however; if I did an installutil /u
changed the app.config file (in the bin) and re-installutil-ed it - it
worked.
I then tried installing the app using the package I created. I then went to
that directory and tried the above (uninstall, edit, reinstall) without
luck.
My purpose in using the app.config file, is to point the service to the
location of a different configuration file (as I need the service to monitor
that file)

I'm quite sure it isn't a problem with my code, but would be happy to

post it if necessary.

Am I right that the app.config file is read once, when the service starts? Or just when it's installed (which seems pointless)

I've been hunting around google and msdn, but not having any luck.


Yes, the config file is read at run time, the first time it's accessed,

not when it's installed. Beyond that, I can't help much because it's not clear what your error is, you say "it doesn't work" but you didn't tell us what
you mean by that. Is an exception being thrown? Are you getting back
unexpected values?

Nov 16 '05 #3

"Tom B" <sh*****@NOSPAMhotmail.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Thanks for the reply, I guess I wasn't clear.

The service doesn't start, and errors out, because the value of my string
(read from app.config) is empty.

I don't have the source code with me, but my string(a file location) is read from the app.config. I know it's not getting populated because my Error Log (where I sent any errors) shows FileNotFoundException.

Does the config file contain a complete file specification? It could be
that the file isn't found because services start with a default directory
that's in the system root, not the directory where your executable is
installed.
Thanks
TomB
"John Vottero" <Jo**@mvpsi.com> wrote in message
news:un**************@TK2MSFTNGP09.phx.gbl...
"TomB" <sh*****@hotmailXXX.com> wrote in message
news:OX**************@TK2MSFTNGP09.phx.gbl...
I've written a simple service that reads the app.config file on start.

It works fine if I start it from the VS IDE -- F5 then installutil

I then created a package, wherein the content of app.config has "" for the values. With the idea that my user, can enter the information before
starting the service. However; this doesn't work. I'm very confused.

As a test, I "emptied" the app.config file and rebuilt, then did an
installutil. This recreated the error, however; if I did an installutil
/u
changed the app.config file (in the bin) and re-installutil-ed it - it
worked.
I then tried installing the app using the package I created. I then went
to
that directory and tried the above (uninstall, edit, reinstall)
without luck.
My purpose in using the app.config file, is to point the service to the location of a different configuration file (as I need the service to

monitor
that file)

I'm quite sure it isn't a problem with my code, but would be happy to

post it if necessary.

Am I right that the app.config file is read once, when the service starts? Or just when it's installed (which seems pointless)

I've been hunting around google and msdn, but not having any luck.


Yes, the config file is read at run time, the first time it's accessed,

not
when it's installed. Beyond that, I can't help much because it's not

clear
what your error is, you say "it doesn't work" but you didn't tell us

what you mean by that. Is an exception being thrown? Are you getting back
unexpected values?


Nov 16 '05 #4
This is just a reminder that when you build a service with .Net, the
App.config file gets copied into an applicationname.exe.config file.
Rebuild in development mode automatically updates this copy, so it
appears like it's reading App.config directly, but it is not. Instead,
look for a *.config file in the bin directory. If you use
System.Configuration to read the AppSettings in the OnStart event, this
is the file being read. You can change the file, stop the service,
start the service, and use the new configuration setting without
uninstalling and reinstalling.

I typically write to an event log during startup so I can verify that
the directory in the config file loaded properly.

Thanks,
Dale
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: | last post by:
Hi, I have a Windows Service that uses a referenced dotnet-dll. In my dll I set some public string to a stringvalue that I get from reading a xml-file(my config file). It works fine if I use it...
1
by: Vlad | last post by:
Is there any way to install multiple instances of the same windows service designed with VS.NET 2003? I tried copying the binaries into a separate folder and then copying registry entries for the...
2
by: Fadi | last post by:
Backround: I am trying to figure out how to do the equivalant of a classic COM Local Server Singleton in .NET/C#. I created a coupld of simple Class Libs that exposes public interfaces and hosted...
2
by: Vinoth Kumar | last post by:
hi all i wrote a windows service. i am trying to get it to use an app.config file. unfortunately, when the service starts, it assumes that the ConfigurationSettings file is in...
6
by: Leonardo Curros | last post by:
Hello, I would like to know what's the best way to restart one service. I would like to do it from the service itself. Is this possible? I try it with ServiceController.stop()...
3
by: John Fred | last post by:
Salve, I have write a service Windows for the remoting. I have a dll Server (OLD COM+) For Configure DLL Server I user Config File Es. <configuration> <system.runtime.remoting>...
4
by: PeterW | last post by:
I have a Windows service that needs to get some values from a config file. I place the config file for the service in the System32 directory. I do not get the values using the usual...
4
by: =?Utf-8?B?QmlsbCBNaWxk?= | last post by:
Feel free to let me know if there is a better place to post this question I'm a website developer trying to write a Windows Service, and I think I'm running into trouble due to the paradigm...
14
by: Peter | last post by:
..NET 3.5 I have a Windows Service application and it does remoting, but when a client incounters an error the client get the following error message "Server encountered an internal error....
1
by: =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post by:
Hi, I created a web service that I want to host in windows service. The problem is that if I host it as windows service it does not use the configuration file. I have to define the binding,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.