Getting the Exceptions HResult value in .net 4 or earlier
Posted on 2015-02-18
An exception has a HResult property. From .net 4.5 onwards the getter is public but in .net 4 or earlier it is protected.
I want to trap an explicit (Microsoft) exception and suppress the default warning message so the obvious way is:
if(e.HResult == ....
but this won't compile in a .net 4 based app because the e.HResult is protected.
So is there a simple workaround to extract the HResult value in a .net 4 based app?
(The app will run on English and non-English operating systems so I can't rely on the text of the message).