[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
https://bugzilla.novell.com/show_bug.cgi?id=467415
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 =
domain.DefineDynamicAssembly(asmName,
AssemblyBuilderAccess.RunAndSave);
// 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 =
demoAssembly.DefineDynamicModule(asmName.Name,
asmName.Name+".dll");
TypeBuilder demoType =
demoModule.DefineType("DemoType", TypeAttributes.Public);
MethodBuilder factory =
demoType.DefineMethod("Factory",
MethodAttributes.Public | MethodAttributes.Static);
string[] typeParameterNames = {"T"};
GenericTypeParameterBuilder[] typeParameters =
factory.DefineGenericParameters(typeParameterNames);
GenericTypeParameterBuilder T = typeParameters[0];
Type[] parms = {};
factory.SetParameters(parms);
factory.SetReturnType(T);
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);
ilgen.Emit(OpCodes.Ret);
// Complete the type.
Type dt = demoType.CreateType();
// Save the assembly, so it can be examined with Ildasm.exe.
demoAssembly.Save(asmName.Name+".dll");
MethodInfo m = dt.GetMethod("Factory");
MethodInfo bound = m.MakeGenericMethod(typeof(int));
// Display a string representing the bound method.
//Console.WriteLine(bound);
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:
http://lists.ximian.com/pipermail/mono-devel-list/2008-August/028942.html
--
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