[Mono-bugs] [Bug 591727] New: Using typeof on nested generic classes throws runtime exception

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Mar 28 16:43:21 EDT 2010


http://bugzilla.novell.com/show_bug.cgi?id=591727

http://bugzilla.novell.com/show_bug.cgi?id=591727#c0


           Summary: Using typeof on nested generic classes throws runtime
                    exception
    Classification: Mono
           Product: Mono: Compilers
           Version: unspecified
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: mcloughlin77 at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Community User
           Blocker: No


If you have two classes that are generic with one of them being a sub-class of
the other then when you attempt to use the typeof operator without qualifying
the full class path the runtime will throw a System.TypeLoadException.

The following code will reproduce the issue:

using System;
namespace MonoTest {
    public class Foo<T> {
        public class Bar<U> { }
        public Type Works() { return typeof(Foo<>.Bar<>); }
        public Type Broken() { return typeof(Bar<>); }
    }

    class Program {
        static void Main(string[] args) {
            var foo = new Foo<double>();
            foo.Works();
            foo.Broken();
        }
    }
}

The above code work properly when compiled with Microsoft's compiler and
executed with the mono runtime.  As shown above, the work around is to use the
fully qualified class declaration.

-- 
Configure bugmail: http://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