How do I determine the HResult for a System.IO.IOException?
For .Net Framework 4.5 and above, you can use the Exception.HResult
property:
int hr = ex.HResult;
For older versions, you can use Marshal.GetHRForException
to get back the HResult, but this has significant side-effects and is not recommended:
int hr = Marshal.GetHRForException(ex);
For what it's worth, System.Exception.HResult is no longer protected in .NET 4.5 -- only the setter is protected. That doesn't help with code that might be compiled with more than one version of the framework.