[Mono-dev] ObjectDisposedException etc lacks #ctor(String, Exception)

Andy Hume andyhume32 at yahoo.co.uk
Tue Dec 19 08:17:55 EST 2006

I was using 
    new ObjectDisposedException("...", caughtException)
in my code, and thus on Mono it fails at runtime with MissingMethodException as that exception has no "#ctor(string message, Exception inner)" in Mono.

The FDG (Framework Design Guidelines) says:
"Do provide (at least) these common constructors on all exceptions.
public class SomeException: Exception, ISerializable {
  public SomeException();
  public SomeException(string message);
  public SomeException(string message, Exception inner);
  // this constructor is needed for serialization.
  protected SomeException(SerializationInfo info, StreamingContext context);

See http://blogs.msdn.com/kcwalina/archive/2006/07/05/657268.aspx, http://msdn2.microsoft.com/en-gb/library/87cdya3t(vs.80).aspx

I've written some code to detect such differences from the MSFT runtime.  It is attached.  This highlights the following instances of that constructor missing:
In Corlib
* System.ArgumentOutOfRangeException
* System.DuplicateWaitObjectException
* System.NotFiniteNumberException
* System.ObjectDisposedException
In System
* System.ComponentModel.Design.CheckoutException

Other items are where certain constructors are missing in both producer's BCLs, e.g.
* System.Reflection.ReflectionTypeLoadException
* System.Reflection.TargetInvocationException

There are other inconsistencies in the results, but mostly unimportant: differences in messages usage, and two cases where there are *extra* constructors in Mono e.g. in MSFT "ObjectDisposedException - Has NO default constructor", but does in Mono.

The attached code is for a command-line program that outputs cases where there is:
* No #ctor().
* No #ctor(String).
* No #ctor(String,Exception).
* No (public/protected) #ctor(SerializationInfo, StreamingContext).

And also for #ctor(String,Exception):
* Different 'message' than supplied.  The only cases seen being where the exception adds some prefix to the message.
* Diffent 'innerException' than supplied.  None seen.
* (HResults checking is done by code posted previously to mono-devel-list).

I run it on both the MSFT and Mono CLRs and then compare the two outputs.

Sadly I don't have a setup to build Mono, so can't send patches. :-(  I aim to set up building, but may be some time: Windows machine, christmas etc etc.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: MonoBug05ExceptionCtorStringAndException.cs
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20061219/cceca5c0/attachment.pl 

More information about the Mono-devel-list mailing list