I'm trying to split up my main App.config file into multiple files to make it easier for my support guys so the config file they open up every tag will be one that needs to be changed instead of having some that do not need to be changed in there.The following code gets called when the structure is deserialized from the Xml, the parent and hmm are both null and configSection is the XmlNode . When xs.Deserialize gets called it ends up throwing the exception "There are multiple root elements. Line 2, position 2." I'm guessing that this is because in RarelyChanges.config there are multiple root elements. Is there anyway to just have multiple lines of the second Xml document included in the App.config file when I do the xi:include? Sorry if this made little sense, its the end of the day and I'm just tired from trying to figure this out.public object Create( object parent, object hmm, XmlNode configSection ){ object tmpObj = null; tmpObj = xs.Deserialize( new XIncludingReader( new StringReader( configSection.OuterXml ) ) ); return tmpObj;}
App.config
<?xml version="1.0" encoding="utf-8" ?><configuration> <configSections> <section name="application" type="AppStructure"/> <section name="applicationConfigurationManagement" type="Microsoft.ApplicationBlocks.ConfigurationManagement.ConfigurationManagerSectionHandler,Microsoft.ApplicationBlocks.ConfigurationManagement, Version=1.0.0.0,Culture=neutral,PublicKeyToken=c14a5885e5232caa" /> </configSections> <application xmlns:xi="http://www.w3.org/2001/XInclude"> <AppStructure xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <xi:include href="RarelyChanges.config" /> <NumberOfDays>7</NumberOfDays> </AppStructure> </application> <applicationConfigurationManagement defaultSection="application" > <configSection name="application"> <configCache enabled="false" refresh="1 * * * *" /> <configProvider assembly="Microsoft.ApplicationBlocks.ConfigurationManagement,Version=1.0.0.0,Culture=neutral,PublicKeyToken=c14a5885e5232caa" type="Microsoft.ApplicationBlocks.ConfigurationManagement.Storage.XmlFileStorage" signed="false" refreshOnChange="true" encrypted="false" /> </configSection> </applicationConfigurationManagement></configuration>
RarelyChanges.config
<NumberOfMonths>12</NumberOfMonths><NumberOfWeeks>52</NumberOfMonths>
I guess I would like the <AppStructure> part of the final version of App.config to "look" something like this
<AppStructure> <NumberOfMonths>12</NumberOfMonths> <NumberOfWeeks>52</NumberOfMonths> <NumberOfDays>7</NumberOfDays></AppStructure>
Well, I have still not been able to come up with a solution for splitting my config file into multiple files which will work with the XmlSerializer.Deserialize method.
Stepping through the generated XmlSerializer code and watching it attempt to deserialize the xml is simply frustrating because it appears like it should be working (in watch window if statements are looking like they are true but get stepped over). I did figure out how to have my external app config set up and the main app.config pointing towards it using the xpointer part of XInclude.
I think I'm just going to look into generating a temporary .config file now by combining external config files whenever I need to use the App.config file. Probably not the best solution to this problem but since I'm at the point where it really seems like it should be working how it is set up and it isn't I'm at a lost of what to try next.