I recently added a configuration section to my App.confg file. Although I realize the section was invalid, my application actually ran, up until it hit this line:
this.udpClient = new UdpClient();
at which point it gave the following exception:
System.Configuration.ConfigurationErrorsException
with the message:
"Configuration system failed to initialize"
and inner exception message (same type of exception):
"Unrecognized configuration section AppDefaults. (<filename goes here>)"
Why does instantiating a UdpClient access your app config, and why does it throw a configuration exception, instead of a Socket Exception (with inner configuration exception), like the method states it will?
The reason that it was trying to access the config when creating the UdpClient object is because the UdpClient and TcpClient classes are only wrappers around the Socket classes. The Socket class has a configuration section for it where socket settings can be stored and read from the config file. Since there was a problem with the config file and it was invalid you received the configuration exception when it was trying to look for that section in the config file. It makes sense because the problem was with reading the config file before it even gets to create the underlying Socket.
Link to MSDN info on Sockets Configuration Section