asp.net - How to use sections in an app.config that's in a web.config? -


my web.config looks this:

<configuration>   <configsections>     <appsettings configsource="exampleapp.config" />     <connectionstrings configsource="exampleprod.config" />   </configsections> <configuration> 

my app.config (exampleapp.config) looks this:

<configsections>   <sectiongroup name="examplesettings">     <section name="blah" type="system.configuration.namevaluesectionhandler" />     <section name="foo" type="system.configuration.namevaluesectionhandler" />   </sectiongroup> </configsections> <examplesettings>   <blah>     <add key="me" value="1" />   </blah>   <foo>     <add key="you" value="2" />   </foo> </examplesettings> 

i'm getting error says: xml document cannot contain multiple root level elements. how resolve this?

as error specifies, need have 1 root element in xml file. put 2 parent elements in 1 parent element like,

<rootele>  <configsections>   <sectiongroup name="examplesettings">      <section name="blah" type="system.configuration.namevaluesectionhandler" />      <section name="foo" type="system.configuration.namevaluesectionhandler" />   </sectiongroup> </configsections> <examplesettings>   <blah>      <add key="me" value="1" />   </blah>   <foo>      <add key="you" value="2" />   </foo> </examplesettings>  </rootele> 

it should work.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -