[Mono-dev] Inconsistent HResult setting in two BCL Exceptions

Andy Hume andyhume32 at yahoo.co.uk
Tue Dec 19 05:03:37 EST 2006


In doing some work to check what Exception constructors are missing I noted that the HResult value is set manually in each constructor, and wondered if it was set correctly in each constructor in each exception type.

I produced the attached program to check this.  It shows two cases in Corlib:

* System.ArgumentNullException
Inconsistent HResult, was 80004003, now 80070057.
    (Params: {String message, Exception innerException})

* System.NotFiniteNumberException
Inconsistent HResult, was 80070216, now 80131528.
    (Params: {Double offendingNumber})
Inconsistent HResult, was 80070216, now 80131528.
    (Params: {String message})
Inconsistent HResult, was 80070216, now 80131528.
    (Params: {String message, Double offendingNumber})
Inconsistent HResult, was 80070216, now 80131528.
    (Params: {String message, Double offendingNumber, Exception innerException})

These are simply fixed by copying to "public ArgumentNullException (string message, Exception innerException)" the respective line from a neighbour constructor, and similarly to "public NotFiniteNumberException ()", in fact in both cases the line is
			HResult = Result;

(I wonder if there's some better pattern that can be used so that the explict setting is not required...?)


In System.dll there is one false positive, Win32Exception which reads the HResult value from Marshal.GetLastWin32Error(), so depends on the state of the environment.  I attempted to solve this by P/Invoking something that will always fail.  However there is apparently something else failing with error code 0x80131501 in the Mono environment.


Which other of the assemblies should this be called on?
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: MonoBug05bExceptionHresultConsistency.cs
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20061219/41c83089/attachment.pl 


More information about the Mono-devel-list mailing list