The Configuration Section Cannot Contain a CDATA or Text Element
That exception usually means your .config file has raw text or a CDATA block where only XML elements are allowed. In .NET config files, sections must contain well-formed child elements, not plain text.
Ok, you have got an error message "The configuration section cannot contain a CDATA or text element" announced from a C# application while you're debugging on Visual Studio.
If you search this error message on search engines, you will see that there is not any useful advice that would help you to solve the issue.
However, the solution is not a complex one.
Probably, you have mistakenly done a rogue key-press in App.config (web.config) file and save it.
Check the folowing example:
<configuration>
<appSettings>
<add key="SomeKey" value="Some Value"/>s
</appSettings>
</configuration>
The developer tries to add a new key ("SomeKey") to appSettings of App.Config file. After that, he/she tries to save the file by clicking Ctrl+S. But, he mistakenly adds an "s" character to the file.
Such an edit throws the mentioned error message.
So, check your app.config (web.config) file, to find a phrase that breaks down the xml standards.
I hope, this will solve your "The Configuration Section Cannot Contain a CDATA or Text Element" problem.
Common places this happens
1. Wrong section structure
Each section has strict rules:
• <appSettings> → only <add> elements
• <connectionStrings> → only <add> elements
• Custom sections → must follow their schema
2. Copy-pasting XML or JSON inside config
People sometimes try:
<appSettings>
<add key="MyJson">
{ "name": "John" }
</add>
</appSettings>
This breaks because the value must be an attribute, not inner text.
Fix:
<add key="MyJson" value='{"name":"John"}' />
3. CDATA inside restricted sections
Even though XML allows CDATA, many .NET config sections (handled by System.Configuration) do not permit it.
How to fix quickly?
• Open your App.config or Web.config
• Find the section mentioned in the exception
• Remove:
- Any
- Any raw text between tags
• Ensure everything is inside proper XML elements/attributes