[Mono-bugs] [Bug 335011] Runtime crashes when emitting generics code

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Oct 25 11:50:47 EDT 2007


Rodrigo Kumpera <rkumpera at novell.com> changed:

           What    |Removed                                         |Added
                 CC|                                                |rkumpera at novell.com

--- Comment #2 from Rodrigo Kumpera <rkumpera at novell.com>  2007-10-25 09:50:47 MST ---
This bug is due to the way GetMethod works for generic instances of

Here is what happens:

Type GObj = G.MakeGenericType(new Type[] { typeof(object) });
//GObj is an instance of MonoGeneriClass.

TypeBuilder.GetMethod (Type instanciated, MethodInfo meth)
   instanciated.GetMethod (meth);

//This will trigger:
MonoGeneriClass.initialize -> reflection.c /


MonoGeneriClass.GetCorrespondingInflatedMethod -> icall.c /

When the second call to TypeBuilder.GetMethod is made, initialize won't be

mono_reflection_generic_class_initialize setup the mhandle (a MonoMethod*)
field of all MethodBuilder. This is required for GetCorrespondingInflatedMethod
to work.

What happens is that the second MethodBuilder is created after
MonoGeneriClass.initialize() is called so it's mhandle field will be null and
cause the segfault.

This problem could cause weird problems if, for example, the MethodBuilder
signature is changed after a MonoGenericClass::initialize() is called - we
could have inflated methods with incompatible signatures.

The token can be computed by using MethodBuilder::table_idx. But this won't
solve the issue since once MonoGenericClass::initialize() is called new methods
added to the TypeBuilder won't show up on the MonoGenericClass.

It's not all bad news, there is one work-around. If you add all members before
calling TypeBuilder::MakeGenericType, everything should work just fine. This is
very restrictive, as it would not allow to have a generic instantiation as
field or parameter.

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list