HRESULT
TransformationsEvery .NET exception type has a protected HResult
field that is exposed to COM as an HRESULT
when the exception is thrown. This appendix lists the HRESULT
value for every .NET exception defined in the .NET Framework—more than just the mscorlib
assembly.
Table D.1 lists the HRESULT
s numerically, answering a COM programmer’s question, “What .NET exception was likely thrown to cause this failure HRESULT
?” Some of this information can be obtained programmatically by calling the System.Runtime.InteropServices.Marshal.ThrowExceptionForHR
method, but only for a subset of the HRESULT
s. The word “likely” is used because, in general, it’s impossible to know what .NET exception was thrown from an HRESULT
value alone. This is true because:
• Many .NET Framework exception types reuse the same HRESULT
value.
• Future user-defined exceptions could reuse HRESULT
values.
• Any exceptions deriving from System.Runtime.InteropServices.ExternalException
have a public ErrorCode
property that enables anyone to change the HRESULT
value at any time.
Table D.1. HRESULT
s Listed Numerically
Table D.2 contains the same information as Table D.1 but lists the exception types alphabetically, to answer a .NET component author’s question, “If I throw this exception, what HRESULT
will a COM client see returned?” This information can always be obtained for any .NET exception by calling System.Runtime.InteropServices.Marshal.GetHRForException
(which simply returns the value in the exception’s protected HResult
field).
Here are a few notes about the tables:
• For exception types that share the same HRESULT
values, the bold types in Table D.1 correspond to the ones thrown when the HRESULT
is returned from COM and exposed to .NET as an exception (shown in Appendix C).
• The italicized exception types derive from (or are) System.Runtime.InteropServices.ExternalException
, indicating that their HRESULT
values could be easily set to any value—not just the values listed.
• Some exception types listed in Table D.2 have no default HRESULT
value; they are always constructed with a value specific to an error-causing situation. These six exception types are not listed in Table D.1.
• Any listed names beginning with ERROR
are Win32 error codes that must be added to 0x80070000 to get the listed HRESULT
value with FACILITY_WIN32
.
• A few HRESULT
s have multiple names, because some .NET HRESULT
s (beginning with COR
) are defined with the same value as classic COM HRESULT
s. A list of named .NET HRESULT
s can be found in CorError.h
.