Skip to content

TypeDelegator members DeclaringType is not the parent type #69244

Closed

Description

@LakshanF

In NativeAOT, a type wrapped in TypeDelegator has issues with its members parent type.

The data passed for this test scenario fails due to this. A simple repro is shown below with the output from .NET and NativeAOT

using System;
using System.Reflection;

public class Program
{
    static void Main(string[] args)
    {
        BindingFlags all = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
        Type t1 = new TypeDelegator(typeof(U_T<>));
//        Type t1 = typeof(U_T<>); //commenting this in and commenting the above line out will make the repro works as .NET
        var m1 = t1.GetMembers(all)[0];
        Console.WriteLine($"(t1): <{t1.Name}>");
        Console.WriteLine($"MemberInfo (m1): <{m1.Name}>");
        Console.WriteLine($"m1.DeclaringType.Equals(t1): <{m1.DeclaringType.Equals(t1)}>");
        Console.WriteLine($"t1.GetType().FullName: <{t1.GetType().FullName}>");
        Console.WriteLine($"t1.UnderlyingSystemType.GetType().FullName: <{t1.UnderlyingSystemType.GetType().FullName}>");
        Console.WriteLine($"m1.DeclaringType.GetType().FullName: <{m1.DeclaringType.GetType().FullName}>");
        Console.WriteLine($"m1.DeclaringType.UnderlyingSystemType.GetType().FullName: <{m1.DeclaringType.UnderlyingSystemType.GetType().FullName}>");
    }

    public class U_T<T>
    {
    }
}

NativeAOT Output

(t1): <U_T`1>
MemberInfo (m1): <.ctor>
m1.DeclaringType.Equals(t1): <False>
t1.GetType().FullName: <System.Reflection.TypeDelegator>
t1.UnderlyingSystemType.GetType().FullName: <$BlockedFromReflection_0_c437915f>
m1.DeclaringType.GetType().FullName: <$BlockedFromReflection_0_c437915f>
m1.DeclaringType.UnderlyingSystemType.GetType().FullName: <$BlockedFromReflection_0_c437915f>

,NET Output

(t1): <U_T`1>
MemberInfo (m1): <.ctor>
m1.DeclaringType.Equals(t1): <True>
t1.GetType().FullName: <System.Reflection.TypeDelegator>
t1.UnderlyingSystemType.GetType().FullName: <System.RuntimeType>
m1.DeclaringType.GetType().FullName: <System.RuntimeType>
m1.DeclaringType.UnderlyingSystemType.GetType().FullName: <System.RuntimeType>

Activity

  1. ghost added
    untriaged
    on May 12, 2022
  2. added this to the 7.0.0 milestone on May 31, 2022
  3. ghost removed
    untriaged
    on May 31, 2022
  4. modified the milestones: 7.0.0, 8.0.0 on Aug 8, 2022
  5. ghost added
    untriaged
    on Aug 8, 2022
  6. removed
    untriaged
    on Aug 8, 2022
  7. modified the milestones: 8.0.0, Future on Oct 27, 2022
  8. added
    in-pr
    on Aug 26, 2025
  9. locked and limited conversation to collaborators on Sep 26, 2025
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-NativeAOT-coreclrin-pr

    Type

    No type

    Projects

    • Status
      No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions