Skip to content
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

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

Closed
stephentoub opened this issue Aug 9, 2022 · 8 comments · Fixed by #89061
Assignees
Labels
area-TypeSystem-coreclr in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@stephentoub
Copy link
Member

stephentoub commented Aug 9, 2022

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?

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Aug 9, 2022
@stephentoub stephentoub added this to the 7.0.0 milestone Aug 10, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Aug 10, 2022
@mangod9
Copy link
Member

mangod9 commented Aug 10, 2022

@trylek / @davidwrighton if this is expected?

@trylek
Copy link
Member

trylek commented Aug 10, 2022

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

@mangod9
Copy link
Member

mangod9 commented Aug 15, 2022

moving to 8 to reduce churn at this point.

@mangod9 mangod9 modified the milestones: 7.0.0, 8.0.0 Aug 15, 2022
@danmoseley
Copy link
Member

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

@silkfire
Copy link

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

@aepot
Copy link

aepot commented Aug 21, 2022

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.

@trylek
Copy link
Member

trylek commented Aug 21, 2022

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.

@trylek trylek self-assigned this Aug 21, 2022
@Joe4evr
Copy link
Contributor

Joe4evr commented Nov 25, 2022

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.

@davidwrighton davidwrighton self-assigned this Jun 23, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 18, 2023
davidwrighton added a commit that referenced this issue Jul 19, 2023
… constraints (#89061)

- The major problem was the logic which incorrectly would instantiate the methods when it wasn't necessary
- As the number of flags to the implementation functions has grown very large, this change also includes logic converting them all to a single flags variable when passing them around

Fixes #73658
Fixes #78865
@ghost ghost locked as resolved and limited conversation to collaborators Aug 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-TypeSystem-coreclr in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
8 participants