C# – How to read a custom class from app.config with an automatic loader

It’s tedious to manually map settings from appSettings to your own class. You may have looked for ways to load your own custom class. The official documentation that explains how to do this is overly complicated. They would have you inheriting from ConfigurationSection, etc…, which is way too much effort. Why bother with all of … Read more

C# – Use Convert.ChangeType to convert string to any type

You can use Convert.ChangeType() to convert from a string to any type, like this: Normally you’d call the specific type converter method, like Convert.ToBoolean(“true”). However, sometimes it makes sense to use the generalized type converter method – Convert.ChangeType() – instead of hardcoding the calls to specific type converter methods. I’ll show an example of when … Read more

How to modify app.config at runtime

When you try to modify the app.config at runtime, if you don’t do it right, you’ll run into a few problems: You’ll get the following exception: System.Configuration.ConfigurationErrorsException: The configuration is read only. The updated value isn’t persisted. When you re-open your program, the value you changed is still the old value. This article will show … Read more