Quick fix for 'Unrecognized configuration section system.diagnostics' error in .NET apps

.NET can be used to create a variety of different types of app, coming with various technologies such as WPF and Windows Forms to help you create them. .NET apps support providing a .config file with the app that can be used to store various bits of configuration information about the app. There is an issue, however, that you might encounter when adding this file to your project (either manually or automatically, such as when you create a .settings file). The issue is that this file can cause a System.Configuration.ConfigurationErrorsException exception, with an error message that starts with something like 'Unrecognized configuration section system.diagnostics'. Luckily, there is an easy fix for this issue which simply involves adding a single line of code to your config file.

The Fix

So, to fix the issue, first open your project's configuration file (it will probably be named app.config or something like that) and add the following line under <configSections>:

<section name="system.diagnostics" type="System.Diagnostics.DiagnosticsConfigurationHandler"/>

and that's it! Hopefully, the error is fixed for you now. Let us know in the comments if this fix worked for you or if you have any other fixes for this issue. Also, if this guide did help you and you use an AdBlocker and you want to support us, consider disabling it for this site - if you do, it will be greatly appreciated!

Follow us to be notified when we release new guides:


Popular posts from this blog

How to show placeholder text in a WPF TextBox in C# and VB

How to enable dark title bar in WPF and Windows Forms/WinForms apps in C# and VB

How to use modern icons in XAML in WPF on Windows 10 and 11

How to change the colour of a WPF or Windows Forms/WinForms title bar in Windows 11 in C# and VB

Microsoft WebView2: How to check if the WebView2 runtime is installed in C# and VB