Click here to Skip to main content
15,943,008 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends.

I have developed the application in visual studio 2010 which consists of two projects in solution

one is c# windows service application and other is windows application.

i have placed the App.config in windows application project .

While creating the setup of windows application am starting the windows service programattically and the service is installed and working fine.

but in the OnStart Method of windows service is unable to read nor recognize the App.config file and not able to read the connection string in the app.config, every time its returning NULL/Empty value.

Can anybody please guide me on how to approach to read the values from the app.config from windows service.

Any Help greatly appriciated.

Thanks

Goswami
Posted

1 solution

app.config is not recognizable in installed form. Rename the file app.config to yourservicename.exe.config file and check again.
 
Share this answer
 
Comments
goswami.tarun 6-Mar-14 12:06pm    
Hi Syed,
I want to use same app.config file for both Window Application and Windows Service.
So, Is there any way to achieve this target?
_Asif_ 6-Mar-14 12:14pm    
You can have one app.config but you have to deploy two app.config with respective names in both application deployments.
goswami.tarun 6-Mar-14 12:28pm    
Actually I am new in Windows Service So, I just added a window service reference to my window application and then deploy the window application and install that service pragmatically by override the install method in custom installer class.
Is it the right way i choose if not please suggest me something else.
Sergey Alexandrovich Kryukov 6-Mar-14 14:52pm    
I don't know why would you need that, but one option is to develop project which acts as a Service and as the interactive application at the same time, depending one which host starts it. They it would be one application instead of two. I've don it for way more important purpose: the ease of debugging. Most debugging has been done in interactive mode, which, quite apparently, much easier.
—SA
_Asif_ 6-Mar-14 12:41pm    
No this is not the right way of Installing Windows Services. Please check below url for starting point.

http://msdn.microsoft.com/en-us/library/ddhy0byf(v=vs.110).aspx

http://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900