The configuration section cannot contain a text or CDATA element

Asked

Viewed 827 times

2

The error started to appear when I added the variable:

 <add key="Teste" value="true"/>

Whole Config App.:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
   <appSettings>
   <add key="Teste" value="true"/>
     </appSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="x86"/>
    </assemblyBinding>
  </runtime>
</configuration>

C#:

if (Convert.ToBoolean(ConfigurationManager.AppSettings["Teste"]))

Does anyone know what it might be? Thanks

1 answer

0


I ran some tests here and in your section appSettings is coming with a white space and this is causing the error as there is a text element in the section, the white space. see in the image below

inserir a descrição da imagem aqui

After removing this space the error stopped happening

See more about CDATA here: What does <! [CDATA []]> in XML?

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.