Skip to content

Bug: Covariant return type TypeLoadException in .NET 5 RC2/rtm.20515.8 SDK #43763

Closed
@amis92

Description

@amis92

Description

Using Covariant Return Types from C#9 results in a runtime TypeLoadException.

This is not a duplicate of #41571 as it happens on runtimes from RC2 and 5.0.100-rtm.20515.8 SDK (win-x64).

Repro at: https://github.com/amis92/testnet5/

Repro comes down to the following:

class Program
{
    static void Main(string[] args)
    {
        CallB();
    }

    static void CallB() => new B();
}

abstract class A<T>
{
    public abstract A<T> M();
}

class B : A<string>
{
    public override B M() => new B();
}

I've minimized my original problem where my own class was used as type parameter instead of the string but other than that it's what I've stumbled upon in my code.

Configuration

SDK installed 2020-10-23 from https://aka.ms/dotnet/net5/5.0.1xx/daily/Sdk/dotnet-sdk-win-x64.exe

.NET SDK (reflecting any global.json):
 Version:   5.0.100-rtm.20515.8
 Commit:    d4436c7f87

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18363       
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.100-rtm.20515.8\

Host (useful for support):
  Version: 5.0.0
  Commit:  2d8e19f188

Regression?

No, bug in a new feature.

Other information

Output running repro on runtime in SDK 5.0.100-rtm.20515.8:

.NET 5.0.0
Unhandled exception. System.TypeLoadException: Return type in method 'B.M()' on type 'B' from assembly 'CovariantReturnBugRC2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not compatible with base type method 'A`1[System.__Canon].M()'.
   at Program.CallB()
   at Program.Main(String[] args) in C:\Users\Amadeusz\Source\Repos\testnet5\Program.cs:line 7

It seems the fix in #41703 didn't take some generic stuff into account by the looks of it. And the repro works fine for int as type parameter (class B : A<int>).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions