Skip to content

BadImageFormatException using c# 9 override + generics #54719

Closed

Description

@michaelcheers

Description

See on DotNetFiddle: https://dotnetfiddle.net/2xzsry

new Derived();

public class IA { }
public class IB { }

public abstract class Base
{
    public abstract IA Key { get; }
    public abstract IB Value { get; }
}
public sealed class Derived : Base<IB>
{
    public class A : IA { }
    public sealed override A Key => default;
}
public abstract class Base<B> : Base where B : IB
{
    public sealed override B Value => null;
}

Configuration

Latest .NET 5 & .NET 6.0 preview

Other information

BadImageFormatException
An attempt was made to load a program with an incorrect format.

Activity

  1. ghost added
    untriaged
    on Jun 25, 2021
  2. changed the title [-]BadImageFormatException[/-] [+]BadImageFormatException using c# 9 override + generics[/+] on Jun 25, 2021
  3. huoyaoyuan commented on Jun 25, 2021

    @huoyaoyuan
    Member

    Certain bug about covariant return was identified in the first release of 5.0. Can you confirm they are on the latest patch? The bugs were fixed in patch versions.

  4. hez2010 commented on Jun 25, 2021

    @hez2010
    Contributor

    Can reproduce in .NET 5.0.7 and .NET 6 preview 5.

  5. wzchua commented on Jun 26, 2021

    @wzchua
    Contributor

    if you change the order of Key and Value in Base, it runs

    public abstract class Base
    {
        public abstract IB Value { get; }
        public abstract IA Key { get; }
    }
  6. ghost added
    in-pr
    on Jun 27, 2021
  7. ghost removed
    in-pr
    on Jun 28, 2021
  8. ghost locked as resolved and limited conversation to collaborators on Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-TypeSystem-coreclruntriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions