+ static void HackCorlib ()
+ {
+ if (StdLib)
+ return;
+
+ //
+ // HACK: When building corlib mcs uses loaded mscorlib which
+ // has different predefined types and this method sets mscorlib types
+ // to be same to avoid type check errors in CreateType.
+ //
+ var type = typeof (Type);
+ var system_4_type_arg = new[] { type, type, type, type };
+
+ MethodInfo set_corlib_type_builders =
+ typeof (System.Reflection.Emit.AssemblyBuilder).GetMethod (
+ "SetCorlibTypeBuilders", BindingFlags.NonPublic | BindingFlags.Instance, null,
+ system_4_type_arg, null);
+
+ if (set_corlib_type_builders == null) {
+ root.Compiler.Report.Warning (-26, 3, "The compilation may fail due to missing `{0}.SetCorlibTypeBuilders(...)' method",
+ typeof (System.Reflection.Emit.AssemblyBuilder).FullName);
+ return;
+ }
+
+ object[] args = new object[4];
+ args[0] = TypeManager.object_type.GetMetaInfo ();
+ args[1] = TypeManager.value_type.GetMetaInfo ();
+ args[2] = TypeManager.enum_type.GetMetaInfo ();
+ args[3] = TypeManager.void_type.GetMetaInfo ();
+ set_corlib_type_builders.Invoke (CodeGen.Assembly.Builder, args);
+
+ // Another Mono corlib HACK
+ // mono_class_layout_fields requires to have enums created
+ // before creating a class which used the enum for any of its fields
+ foreach (var e in hack_corlib_enums)
+ e.CloseType ();