C# Windows Service XML

By : Goober
Source: Stackoverflow.com


I have a windows service written in C# that performs some processing based on parsing an XML file and use that data to carry out various tasks. The service also does various bits of logging - which uses settings from an APP.Config file.

The Problem

When the service is compiled, installed and run, the XML file seems to disappear. I'm getting the impression that it is just ignored or something like that.

So far

I've tried using TWO App.Config files, one named App.Config that contains settings for the service, and the other called MyService.exe.config that contains all of the data that was used in the XML file (the idea being that I can parse the XML from a config file that actually gets compiled and appears in my installation directory.


When I do this, all that happens is that ONE config file appears (with the name MyService.exe.config), but it contains the contents of the App.Config file and not the XML data that I want to parse.

What I need

All I want is to have a config file for my settings, and an XML file for my data.


Is this possible? I know the application works as it was originally built as a console application that ran fine.


The application has to be designed this way (as in, I need my data stored as XML, and my settings stored in a config file).


If I could somehow combine the contents of the two files into ONE config file, that would be one way of solving the problem. However, I have tried this and of course I get a "Type Initialisation Exception", as the config file cannot interprate the XML data (probably because the tags are custom and do not form any part of the config schema - or something like that).


Please could someone explain to me if it is possible for me to have an XML file AND a config file that will actually be compiled and stored in my installation directory for the service when it is run?


Custom XML/Data Config File

   <?xml version="1.0" encoding="utf-8" ?> 
  <add name="Name" value = "SV066930" /> 
  <add name="ProcessName" value="notepad.exe" /> 
  <add name="CommandLine" value="C:\\WINDOWS\\system32\\notepad.exe    C:\\WINDOWS\\Profiles\\TA2TOF1\\Desktop\\SimonTest1.txt" /> 

APP.Config Settings File

   <?xml version="1.0" encoding="utf-8" ?> 
     <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=, Culture=neutral, PublicKeyToken=xxxxxxxxxxx" /> 
 <add name="DB" connectionString="Data Source=etc......" /> 

Help greatly appreciated.

By : Goober


The file named App.config in you C# project gets renamed to MyService.exe.config when it is built so you're gonna have to rename your second config file that's all.

This video can help you solving your question :)
By: admin