[Mono-bugs] [Bug 649237] New: Missing The specified field must be declared on the generic type definition

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Oct 26 06:40:13 EDT 2010


https://bugzilla.novell.com/show_bug.cgi?id=649237

https://bugzilla.novell.com/show_bug.cgi?id=649237#c0


           Summary: Missing The specified field must be declared on the
                    generic type definition
    Classification: Mono
           Product: Mono: Class Libraries
           Version: SVN
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: rkumpera at novell.com
        ReportedBy: msafar at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


using System;
using System.Reflection;
using System.Reflection.Emit;

class Program
{
    static void Main ()
    {
        AssemblyName asmname = new AssemblyName ();
        asmname.Name = "sre";
        AssemblyBuilder asmbuild = System.Threading.Thread.GetDomain
().DefineDynamicAssembly (asmname, AssemblyBuilderAccess.RunAndSave);
        ModuleBuilder modbuild = asmbuild.DefineDynamicModule ("modulename",
"sre.exe");

        TypeBuilder myType = modbuild.DefineType ("Sample",
TypeAttributes.Public);

        string[] typeParamNames = { "TFirst" };
        myType.DefineGenericParameters (typeParamNames);

        var nested = myType.DefineNestedType ("nested");
        nested.DefineGenericParameters (typeParamNames);

        var field = myType.DefineField ("field", nested,
FieldAttributes.Public);

        var m = myType.DefineMethod ("test", MethodAttributes.Public);
        m.SetParameters (myType);

        var ilgen = m.GetILGenerator ();
        ilgen.Emit (OpCodes.Ldarg_0);
        ilgen.Emit (OpCodes.Ldnull);
        ilgen.Emit (OpCodes.Stfld, TypeBuilder.GetField (myType.MakeGenericType
(typeof (int)), field));
        ilgen.Emit (OpCodes.Ret);

        var baked = myType.CreateType ();
        nested.CreateType ();

        asmbuild.Save ("sre.exe");

        return;
    }
}

NET throws

System.ArgumentException: The specified field must be declared on the generic
type definition of the specified type.
Parameter name: type
   at System.Reflection.Emit.TypeBuilder.GetField(Type type, FieldInfo field)
   at Program.Main()

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


More information about the mono-bugs mailing list