TypeLoadException for this specific class/interface pattern RRS feed

  • Question

  • I think I just found a rare bug, maybe somewhere in the compiler or the CLR.

    The simple code below will crash with TypeLoadException for .NET Framework 2.0 SP2 (working fine in 2.0 SP1)
    You can replace IClonable with any common interfaces/classes.

    What's going on here?


    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace dotNetBug {
        class Program {
            static void Main(string[] args) {
                Concrete c = new Concrete();            

        public interface ITestable<T> {
            void Test();

        public interface ITestableEx : ITestable<ICloneable> {
            void TestEx();

        public class Base<T> : ITestable<T> {
            public void Test() {

        public class BaseEx<T> : Base<T>, ITestableEx where T : ICloneable {
            public void TestEx() {

        public class Concrete : BaseEx<ICloneable> {
    Wednesday, February 4, 2009 1:16 PM


All replies

  • Ouch, makes my head hurt.  You'll get an interesting compiler error when you change the ITestable interface to this:

        public interface ITestable<T> {
            void Test(T arg);

    The compiler doesn't see that Base<T>.Test(T) is a suitable implementation for ITestableEx<T>.Test(T).  Not sure if I see it, I'd hate to have to write the compiler code that detects that.  Looks like they got it wrong.  You can post this issue to

    Hans Passant.
    Wednesday, February 4, 2009 2:16 PM
  • It looks to me like this issue:

    Generics are the problem here and it is issue in CLR. CLR team is actively working on solution for it.

    -Karel Zikmund
    (Developer on CLR Type System team)
    Wednesday, February 4, 2009 5:13 PM
  • Thanks for a quick reply. Fortunately, I can workaround the issue.
    Hope it'll get fixed soon.
    Wednesday, February 4, 2009 5:44 PM
  • Yes, I hope that we will be able to fix it soon too. Unfortunately it's not a simple fix as it is quite complicated part of CLR code base.
    I plan to update the connect bug with more information soon. If you are interested, please watch the connect issue.


    Wednesday, February 4, 2009 6:08 PM