Skip to content

VerificationException with reflection, static abstract interface methods, and generic constraints #73658

Closed

Description

@stephentoub

This:

internal static class Program
{
    static void Main()
    {
        Type s = typeof(Program).Assembly.GetType("Outer`1+Inner");
        Type i = s.GetInterface("IStatics");
        s.GetInterfaceMap(i);
    }
}

class Outer<TOuter>
{
    struct Inner : IStatics
    {
        public static void M<TInner>() where TInner : IConstraint { }
    }

    interface IStatics
    {
        static abstract void M<TInner>() where TInner : IConstraint;
    }

    interface IConstraint { }
}

throws:

Unhandled exception. System.Security.VerificationException: Method Outer`1+Inner[TOuter].M: type argument 'TInner' violates the constraint of type parameter 'TInner'.
   at System.RuntimeType.GetInterfaceMap(Type ifaceType)

Is that expected?

Activity

  1. ghost added
    untriaged
    on Aug 9, 2022
  2. added this to the 7.0.0 milestone on Aug 10, 2022
  3. ghost removed
    untriaged
    on Aug 10, 2022
  4. mangod9 commented on Aug 10, 2022

    @mangod9
    Member

    @trylek / @davidwrighton if this is expected?

  5. trylek commented on Aug 10, 2022

    @trylek
    Member

    I'll take a look later today once I'm done with another SVM-related bug.

  6. mangod9 commented on Aug 15, 2022

    @mangod9
    Member

    moving to 8 to reduce churn at this point.

  7. modified the milestones: 7.0.0, 8.0.0 on Aug 15, 2022
  8. danmoseley commented on Aug 15, 2022

    @danmoseley
    Contributor

    @silkfire you marked thumbs down. Is this issue affecting you?

  9. silkfire commented on Aug 16, 2022

    @silkfire

    Not directly. It was more to show support to those people who were hoping this would be fixed in the upcoming .NET version.

  10. aepot commented on Aug 21, 2022

    @aepot

    Is that expected?

    8.0.0

    @mangod9 Is it really more than one year needed to say is that expected or bug? :) Sorry if I've misinterpreted the milestone assign.

    I was affected by the issue on .NET 7 (p7). Nothing serious but just curious what was that.

  11. trylek commented on Aug 21, 2022

    @trylek
    Member

    I believe the issue is a bug. The milestone change just means that it's too late in .NET 7 release cycle to fix this especially as we haven't yet identified the correct fix. Once the fix is understood we may be able to fix this in a servicing release.

  12. self-assigned this
    on Aug 21, 2022
  13. Joe4evr commented on Nov 25, 2022

    @Joe4evr
    Contributor

    Welp, I hit this today.

    Not that big a deal for me, since this was an exploratory slab of code, but now I know this behavior is a bug and what I had expected it to do is likely what I want. Shame there's not a clear timeframe on the fix yet, but oh well.

  14. ghost added
    in-pr
    on Jul 18, 2023
  15. added a commit that references this issue on Jul 19, 2023
    d1adf81
  16. ghost locked as resolved and limited conversation to collaborators on Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-TypeSystem-coreclrin-pr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions