API Hall of Shame #2 – Useless Exception Messages
ReflectionTypeLoadException takes the cake with this message:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
This is one of the most frustrating messages to encounter outside of the debugger. What do you think the first thing you are going to do when you hit this in production?….Exactly, look at the LoaderExceptions property, which is impossible without forethought or a debugger.
How could have the loader team improved the usability of this exception ten-fold? By simply outputting the first couple of entries from the property:
Unable to load one or more of the requested types. The first few exceptions are provided below. Retrieve the LoaderException property for more information.
---> Could not load file or assembly ‘Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8e9c13fee402ae29' or one of its dependencies. Strong name validation failed.
Much better. Straight away the user can see the root cause of the problem and can react without needing to attach a debugger.
(As a side note, CompositionException in MEF used to suffer from the same problem when I first arrived on the team; luckily, our latest release fixes this)