Skip to content

Multiple default implementation properties in an interface, applied to an abstract hierarchy, causes TypeLoadException #44533

Closed
@vslee

Description

@vslee

Description

Consider an interface which uses the default implementation feature on some temporary variables. If too many (5+) of those variables are used, and the interface is applied to an inheritance hierarchy which contains an abstract ancestor, then a reflection type bug is exposed. Please see the code example below (doing any of the three things in the code comments fixes the problem):

Configuration

Target framework: .NET 5.0 RTM
Operating system: Windows 10 Pro 20H2 x64
IDE: Visual Studio 2019 16.8.0

Regression?

Does not seem to be a regression as the same issue occurred in .NET core 3.1

Other information

using System.Linq;

namespace BugInReflection
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = typeof(Program).GetProperties().Select(e => e.GetIndexParameters()).ToList();
        }

        public BlogPost BlogPost { get; set; }
    }

    public interface ITitle
    {
        // commenting out one or more of these NotMapped properties fixes the problem
        public string Temp1 => "abcd";
        public string Temp2 => "abcd";
        public string Temp3 => "abcd";
        public string Temp4 => "abcd";
        public string Temp5 => "abcd";

        public string Title { get; set; } // commenting out this property also fixes the problem
    }

    public abstract class Post : ITitle // making this non-abstract also fixes the problem
    {
        public string Title { get; set; }
    }
    public class BlogPost : Post { }
}
System.TypeLoadException
  HResult=0x80131522
  Message=Method 'set_Title' in type 'BugInReflection.BlogPost' from assembly 'DefaultImplementationOnAbstract, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
   at System.Reflection.RuntimeMethodInfo.GetParametersNoCopy()
   at System.Reflection.RuntimePropertyInfo.GetIndexParametersNoCopy()
   at System.Reflection.RuntimePropertyInfo.GetIndexParameters()
   at BugInReflection.Program.<>c.<Main>b__0_0(PropertyInfo e) in G:\Google Drive\TestProjects\InterfaceOnDerived\DefaultImplementationOnAbstract\Program.cs:line 9
   at System.Linq.Enumerable.SelectArrayIterator`2.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at BugInReflection.Program.Main(String[] args) in G:\Google Drive\TestProjects\InterfaceOnDerived\DefaultImplementationOnAbstract\Program.cs:line 9

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions