app.config & Win Service

R

Rajesh Abraham

I have an assembly, which is reading some values from the
App.Config file. It works fine when used with a Win Forms
project.

Now I am trying to use the same assembly in a Windows
Service Project but the service fails to start as the
assembly is not able to get the value from the app.config
and hence throws an error. I tried adding app.config to
the Win Service Project but it did not work.

Rajesh Abraham
 
I

Ignacio Machin

Hi,

The thing is that the service runs from C:\Windows\System32 , I think that
you can solve it settig the current directory to your specific directory:

System.IO.Directory.SetCurrentDirectory(
System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileN
ame ) );

This should solve your problem.

hope this help,
 
R

Rajesh Abraham

Thanks for the response. It worked but I was making one
more mistake. I had copied the app.config from my other
project and added it to the solution but it did not work
even after renaming to MyNewApp.exe.config. Finally I had
to add a new text file into the solution and add rename it
as app.config and copy the contents into it and build the
solution again.

Thanks,

Rajesh Abraham
 

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