2

I have been developing a WinService application and testing the methods and functionality using WinForms application.

I have one solution and both applications are under the same solution. Application logic and methods are inside WinService project under public class and methods, so that I can test methods separately.

The WinService application is linked to Windows Forms application using reference. This gives me the opportunity to initialize methods inside WinService applications public class.

Solution
|
|
|--- WinForms
|     |
|     |--- bin
|           |
|           |--- WinForms.exe
|           |--- WinForms.exe.cofig
|           |--- WinService.exe
|            
|--- WinService

The problem is that when using Forms application the app.config changes are not making any difference and values returned are always the same.

I access app.config settings like this

Properties.Settings.Default.App_config_settings_item_name

It seems that when building solution it copies WinService.exe to bin folder of WinForms application, but the app.cofig file is missing.

I have tested to copy this app.config from WinService bin folder, but it doesn't make any difference. It looks like the app.config values are "hard coded" inside WinService.exe and even app.cofig files are not changing those values.

What would be the correct way to use app.config properties?

user4845680
  • 128
  • 2
  • 12
  • I have always found it tough to debug window service applications. What I've always done instead of referencing it as you have, is write all of my application code into a console app first and get it all working, the move all of the code into the windows service app project and log out data to ensure all is working as intended. – mituw16 May 04 '16 at 13:16
  • What is WinService project type? Which project contains settings? How do you save settings? Also it's not related to app.config app.config, because the settings are not stored there. – Reza Aghaei May 04 '16 at 13:29
  • Hi, the project type is "Windows Service" it contains Settins.setting -file and it is in both projects. So this might be the problem that when the referenced project is containing the settings.settings -file the values are stored inside the application? Anyway settings are stored in settings.settings-file which generates app.config changes when edited. – user4845680 May 06 '16 at 05:19

1 Answers1

0

So for trying different thigs I decided to go with <appSettings> solution which I found here

appSettings vs applicationSettings. appSettings outdated?

Even tough it is old style it worked for me in this case. It allowed me to start Windows Service methods and still use settings from Windows Forms application app.cofig. Other possibilty would be external libraries for config reading like Zenini.

Community
  • 1
  • 1
user4845680
  • 128
  • 2
  • 12