[Mono-dev] Unable to catch ArgumentException from constructor in lambda expression

Patrick Timm patrick at isharp.dk
Wed Feb 23 04:16:23 EST 2011


I am using the Samus MongoDB C# driver (Version with some very
simple documents in a mod_mono application.

The following was my original code. It filters the documents in the
(typed) collection "collection" using an Oid (object ID). The
constructor for "Oid" takes a 24 character string. In the following I
supply an invalid ID string which make the Oid.ctor call throw a
System.ArgumentException. However the mod_mono runtime crashes -
bypassing my try..catch.

	// delete the link document with the given ID
	collection.Remove(x => (Oid)x.Id == new Oid("invalidinput"));

catch (ArgumentException)
	// given ID has invalid length (must be 24 characters)

Results in the following stacktrace...

System.ArgumentException: Oid strings should be 24 characters
at MongoDB.Oid.ValidateHex (string) <IL 0x0004b, 0x000d3>
at MongoDB.Oid.ParseBytes (string) <IL 0x00015, 0x00043>
at MongoDB.Oid..ctor (string) <IL 0x00020, 0x0003b>
at (wrapper dynamic-method)
(System.Runtime.CompilerServices.ExecutionScope) <IL 0x00005, 0x00039>
at (wrapper managed-to-native)
(object,object[],System.Exception&) <IL 0x0001c, 0x00068>
at System.Reflection.MonoMethod.Invoke
(object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) [0x000d0] in /tmp/mono/trunk/src/mono-2.6.4/mcs/class/corlib/System.Reflection/MonoMethod.cs:213

Rewriting the code to the following works as expected. The catch is run.

	Oid alala = new Oid("invalidinput");
	// delete the link document with the given ID
	collection.Remove(x => (Oid)x.Id == alala);

catch (ArgumentException)

Is my opinion these code snippets are functionally equal and should both

Is this an error in the mono-runtime, mongo db driver or just me :o)

Kind regards


More information about the Mono-devel-list mailing list