-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple default implementation properties in an interface, applied to an abstract hierarchy, causes TypeLoadException #44533
Comments
Note: this impacts EF Core model building. See dotnet/efcore#23261 |
This is not reflection, it's type system. Reduced repro: using System;
using System.Linq;
namespace BugInReflection
{
class Program
{
static void Main(string[] args)
{
new BlogPost();
}
}
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 { }
} |
I believe the bug is here. runtime/src/coreclr/vm/methodtable.cpp Lines 7960 to 7971 in f3bad4f
|
I'll take a look at this. This isn't something I'm comfortable pushing to 7.0 |
The issue is reproduces under the following situation.
This is permitted in IL, but is a situation which can only be reached with .il code in versions of In .NET 5, this became straightforward to hit with default interface methods. |
- Result of a bad change when removing support for full stub dispatch in .NET 4.0 timeframe (circa 2008) - Caused issue when the following set of conditions were all true - The type implements an interface - The interface has more virtual methods on it than the number of virtual methods on the base type of the type. - The base type implements the interface partially (and the partial implementation has a slot number greater than the number of virtual methods on the base type + its base types) - The type does not re-implement the interface methods implemented by the base type. - The comment referred to situations where stub dispatch was used to resolve non-virtual calls which is a very long time removed feature and is not applicable to today's codebase. - Not reachable with versions of C# that shipped before the default interfaces feature, but with that feature became easily reachable. Has been a bug since .NET 4 for handwritten IL. Fixes dotnet#44533
* Fix type loader not recognizing overridden method - Result of a bad change when removing support for full stub dispatch in .NET 4.0 timeframe (circa 2008) - Caused issue when the following set of conditions were all true - The type implements an interface - The interface has more virtual methods on it than the number of virtual methods on the base type of the type. - The base type implements the interface partially (and the partial implementation has a slot number greater than the number of virtual methods on the base type + its base types) - The type does not re-implement the interface methods implemented by the base type. - The comment referred to situations where stub dispatch was used to resolve non-virtual calls which is a very long time removed feature and is not applicable to today's codebase. - Not reachable with versions of C# that shipped before the default interfaces feature, but with that feature became easily reachable. Has been a bug since .NET 4 for handwritten IL. Fixes #44533
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
reflectiontype 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
The text was updated successfully, but these errors were encountered: