Skip to content

ILC: AV for reflected calls to non-generic static default interface methods #137905

Description

@NinoFloris

Description

Found during hardening of #135169

Reproduction Steps

using System;
using System.Runtime.CompilerServices;

public interface IOperation { static abstract Type Owner(); }
public interface IDefault<T> : IOperation
{
    static Type IOperation.Owner() => typeof(T);
}
public interface IInherited<A, B> : IDefault<B> { }
public class Seed : IOperation { public static Type Owner() => typeof(object); }
public class Program
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    public static Type Call<T>() where T : class, IOperation => T.Owner();
    [MethodImpl(MethodImplOptions.NoInlining)]
    public static Type Callback<T>() where T : class, IOperation => ((Func<Type>)T.Owner)();
    [MethodImpl(MethodImplOptions.NoInlining)]
    static Type Hide(Type type) => type;
    public static int Main(string[] args)
    {
        Console.WriteLine(Call<Seed>());
        Console.WriteLine(Callback<Seed>());

        Type target = Hide(typeof(IInherited<object, string>));
        Type result = args.Length > 0 && args[0] == "delegate"
            ? (Type)typeof(Program).GetMethod(nameof(Callback)).MakeGenericMethod(target).Invoke(null, null)
            : (Type)typeof(Program).GetMethod(nameof(Call)).MakeGenericMethod(target).Invoke(null, null);
        Console.WriteLine(result);
        return result == typeof(string) ? 100 : 1;
    }
}

Expected behavior

Should return typeof(string)

Actual behavior

Process terminated. Access Violation:
Attempted to read or write protected memory.

at IDefault`1.IOperation.Owner()
at Program.CallT
...
at System.Reflection.RuntimeMethodInfo.Invoke(...)

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. dotnet-policy-service commented on Nov 19, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
    See info in area-owners.md if you want to be subscribed.

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

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions