Windows Service and ConfigurationManager

M

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
 
W

Willy Denoyette [MVP]

Myo Zaw said:
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.
 
G

Guest

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
 
G

Guest

sorry,
i misunderstood. it has to be with it's service.exe.config. not
app.config. right?

thanks a lot,
myo zaw
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

It does works fine, my bet is that the filename is incorrect or is not in
the expected location

cheers,
 
W

Willy Denoyette [MVP]

Myo Zaw said:
sorry,
i misunderstood. it has to be with it's service.exe.config. not
app.config. right?

thanks a lot,
myo zaw

Say your service executable is called MyService.exe, then forcibly your
config file should be named MyService.exe.config. Both should be in the same
folder.

Willy.
 
G

Guest

yes,
at first, after i built my service, i copied its exe file to a new
location and install it. didn't work out. but, regarding to willy's
suggestion i copied my app.config file to that location. the same error.
then, i copied my service exe's config to that location and test it.
eventually, work out. thanks so much.

myo zaw
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Just ot point out, a win service cannot just be copied, it needs to be
installed, let me know if you need to know how


cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top