1

This is the app.config in my WPF application:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <section name="XXX.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
        </sectionGroup>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <section name="XXX.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
        </sectionGroup>
      </configSections>

      <userSettings>...</userSettings>
      <applicationSettings>...</applicationSettings>

      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
      </startup>

      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.3.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>

Run application get exception:

ConfigurationErrorsException: Only one element allowed per config file and if present must be the first child of the root element

If I remove <runtime> section application works well but will cause a bulid time warning:

enter image description here

Solution: https://stackoverflow.com/a/46533630/3907561

So my question is How can I make "configSections" "runtime" inside "configuration" work together ?

stuartd
  • 70,509
  • 14
  • 132
  • 163
huang
  • 919
  • 11
  • 22
  • That's confusing. What that error means is "there must be only one configSections section and it must be the first child of the configuration element" but that seems to be the case in your config. Is there another `configSections` declaration in the `` or ``? – stuartd Mar 05 '19 at 15:02
  • Hmm, I wonder if it is because you have declared multiple sectionGroups? – stuartd Mar 05 '19 at 15:06
  • If I remove section, all works well except the build time warning. @stuartd – huang Mar 05 '19 at 15:15

2 Answers2

1

I don't see any problem with using <runtime> and <configSections> together( I did 2 projects with it, and both are OK).

I don't know what are you configuring with bellow sections, maybe your problem is inside them:

      <userSettings>...</userSettings>
      <applicationSettings>...</applicationSettings>
Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
Nhan Phan
  • 1,262
  • 1
  • 14
  • 32
0

Try clean and rebuild the Solution.

huang
  • 919
  • 11
  • 22