-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Description
Describe the bug
If implementing an interface with covariant method result invalid implementation is called. Please see the code sample (better than thousand words, right).
This may be related to mono/mono#7009.
I'm aware that this may be a Mono problem but since I'm unaware of the state of .NET 6 migration I'm posting it here so others may find it easier, please redirect me to the correct repo if needed (Mono or .NET runtime???).
To Reproduce
public interface IFactory<out T>
{
T Get();
}
public class Foo
{
}
public class Bar : Foo
{
}
public class FooFactory : IFactory<Foo>
{
public Foo Get() => new Foo();
}
public class BarFactory : FooFactory, IFactory<Bar>
{
public new Bar Get() => new Bar();
}Test method:
FooFactory c = new BarFactory();
IFactory<Foo> ic = c;
Console.WriteLine($"Result: {ic.Get()}");If I executed as a console app on either .NET 5 or 6 I get Result: Namespace.Bar.
If executed in Blazor I get Result: BlazorDemo.Pages.Counter+Foo (I put this in a razor file for simplicity). Also both .NET 5 and 6.
Further technical details
- ASP.NET Core
5.0.3and6.0.0-preview.1.21103.6
Reactions are currently unavailable