[Mono-bugs] [Bug 75454][Nor] New - [GMCS] NullRef inside
BindGenericParameters when using Type from CreateType ()
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Sun Jul 3 14:43:53 EDT 2005
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by nazgul at omega.pl.
http://bugzilla.ximian.com/show_bug.cgi?id=75454
--- shadow/75454 2005-07-03 14:43:53.000000000 -0400
+++ shadow/75454.tmp.16942 2005-07-03 14:43:53.000000000 -0400
@@ -0,0 +1,99 @@
+Bug#: 75454
+Product: Mono: Runtime
+Version: 1.0
+OS:
+OS Details: mono svn
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs at ximian.com
+ReportedBy: nazgul at omega.pl
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: [GMCS] NullRef inside BindGenericParameters when using Type from CreateType ()
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+There is a problem in binding generic parameters of System.Type returned
+from TypeBuilder.CreateType()
+
+Steps to reproduce the problem:
+1. Compile and run program:
+
+using System;
+using System.Reflection;
+using System.Reflection.Emit;
+
+class M {
+ static void Main () {
+ /// INITIAL ASSEMBLY CREATION
+ AssemblyName name = new AssemblyName();
+ name.Name = "o";
+ AssemblyBuilder builder =
+AppDomain.CurrentDomain.DefineDynamicAssembly(name,
+AssemblyBuilderAccess.RunAndSave);
+ ModuleBuilder mb = builder.DefineDynamicModule("out", "bla.dll");
+ ///////////
+
+
+ /// abstract class Func ['a]
+ /// { public abstract apply () : 'a; }
+ TypeBuilder func = mb.DefineType("Func", TypeAttributes.Abstract);
+ GenericTypeParameterBuilder[] func_gp =
+func.DefineGenericParameters("'a");
+ func.SetParent(typeof (object));
+
+ MethodBuilder func_apply = func.DefineMethod("apply",
+MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual,
+ func_gp[0], new Type[] { });
+
+ Type func_c = func.CreateType();
+
+ /// class Prox : Func[string] {
+ /// }
+
+ // this causes NullRef in BindGenericParameters
+ Type func_string = func_c.MakeGenericType(new Type [] {
+typeof(string)});
+
+ // and this causes InvalidOperation in GetGenericTypeDefinition()
+ // Type func_string = func_c.GetGenericTypeDefinition
+().MakeGenericType(new Type [] { typeof(string)});
+
+ TypeBuilder prox = mb.DefineType("Prox", TypeAttributes.Public);
+ prox.SetParent(func_string);
+
+ prox.CreateType();
+
+ builder.Save("bla.dll");
+ }
+}
+
+Actual Results:
+Unhandled Exception: System.NullReferenceException: Object reference not
+set to an instance of an object
+in <0x00000> <unknown method>
+in (wrapper managed-to-native) System.Type:BindGenericParameters
+(System.Type,System.Type[])
+in <0x00068> System.Type:BindGenericParameters (System.Type[] types)
+in <0x00010> System.Type:MakeGenericType (System.Type[] types)
+in <0x0018d> M:Main ()
+
+Expected Results:
+clear run and valid bla.dll created
+
+How often does this happen?
+Always
+
+Additional Information:
+Also GetGenericTypeDefinition do not work for type returned from CreateType().
+It can be workarounded by using original TypeBuilder instance instead of
+one returned from CreateType, but it is important for us to have the
+created type also working, since some MS.NET bugs are triggered when using
+original TypeBuilder. I hope there is no reason why
+GetGenericTypeDefinition or BindGenericParameters should not work...
More information about the mono-bugs
mailing list