[Mono-bugs] [Bug 467415] New: Mono crashes when accessing fields of generics in dynamic assemblies

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Jan 19 13:04:09 EST 2009


           Summary: Mono crashes when accessing fields of generics in
                    dynamic assemblies
    Classification: Mono
           Product: Mono: Runtime
           Version: SVN
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: generics
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: mprobst at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---

This program should print "0", but it crashes on Mono:

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;

public class Gen<T> {
    public static T field = default(T);

public class main {
    public static int Main () {
        AssemblyName asmName = new AssemblyName("DemoMethodBuilder1");
        AppDomain domain = AppDomain.CurrentDomain;
        AssemblyBuilder demoAssembly = 

        // Define the module that contains the code. For an 
        // assembly with one module, the module name is the 
        // assembly name plus a file extension.
        ModuleBuilder demoModule = 

        TypeBuilder demoType = 
            demoModule.DefineType("DemoType", TypeAttributes.Public);

        MethodBuilder factory = 
                    MethodAttributes.Public | MethodAttributes.Static);

        string[] typeParameterNames = {"T"};
        GenericTypeParameterBuilder[] typeParameters = 

        GenericTypeParameterBuilder T = typeParameters[0];

        Type[] parms = {};


        ILGenerator ilgen = factory.GetILGenerator();

        Type G = typeof(Gen<>);
        Type GT = G.MakeGenericType (T);
        FieldInfo GF = G.GetField("field");
        FieldInfo GTF = TypeBuilder.GetField(GT, GF);

        ilgen.Emit(OpCodes.Ldsfld, GTF);

        // Complete the type.
        Type dt = demoType.CreateType();
        // Save the assembly, so it can be examined with Ildasm.exe.

        MethodInfo m = dt.GetMethod("Factory");
        MethodInfo bound = m.MakeGenericMethod(typeof(int));

        // Display a string representing the bound method.

        object[] parameters = {};
        int result = (int)(bound.Invoke(null, parameters));

        Console.WriteLine("{0}", result);

        return 0;

The problem is that in resolve_object() in reflection.c we don't get the field
of the inflated class.

This bug is responsible for the F# problem reported here:


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