Skip to content

System.Reflection.CustomAttributeFormatException thrown on a retrieval of derived attribute with overridden property getter#117584

Open
pedrobsaila wants to merge 19 commits intodotnet:mainfrom
pedrobsaila:110412-bis
Open

System.Reflection.CustomAttributeFormatException thrown on a retrieval of derived attribute with overridden property getter#117584
pedrobsaila wants to merge 19 commits intodotnet:mainfrom
pedrobsaila:110412-bis

Conversation

@pedrobsaila
Copy link
Contributor

@pedrobsaila pedrobsaila commented Jul 13, 2025

Fixes #110412
Fixes #119490

Sorry for the delay, I've been busy these last weeks

…l of derived attribute with overridden property getter
@pedrobsaila pedrobsaila requested a review from marek-safar as a code owner July 20, 2025 14:41
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Jul 20, 2025
Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@MichalStrehovsky Any further feedback?

@MichalStrehovsky
Copy link
Member

@MichalStrehovsky Any further feedback?

If we really want this, it looks reasonable. For posterity though, this is implementing some of C# language semantics into the runtime reflection stack (the runtime reflection stack doesn't consider property inheritance in general, like I pointed out in #110945 (comment), or how Type.InvokeMember(BindingFlags.SetProperty) works).

IL is more expressible than what C# allows. C# can sometimes get into IL-level corner cases due to NuGet versioning and compile-time seeing different things than runtime.

What is implemented here will allow things like:

[Derived(Prop = 123)]
class Program;

class BaseAttribute : Attribute
{
    public virtual int Prop { get; set; }
}

class DerivedAttribute : BaseAttribute
{
    // Note `new` keyword
    public new virtual int Prop { get => base.Prop; }
}

to work even though the C# compiler would not accept this.

Hopefully this is sufficiently leafy within the reflection stack that it won't affect many things. I'm not worried about this breaking existing apps (because we're just fixing a throw to not throw). However there's is an aspect that if someone does take advantage of this not throwing, they may run into new issues that we didn't consider.

Like I wrote in #110945 (comment) this needed a bit more design discussion to consider these things before we decide whether we really want to fix this.

@jeffhandley
Copy link
Member

@AaronRobinsonMSFT -- I defer to you on this with @MichalStrehovsky's input. I'll assign to you to drive it to closure or merge. Thanks!

@AaronRobinsonMSFT
Copy link
Member

@pedrobsaila I've made some edits on a fork of your branch here. @jkotas helped bring me up to speed on the concerns that @MichalStrehovsky was expressing. I hadn't fully appreciated the issues that this represented. My branch has the following changes:

Please let me know if you're willing to fold in the changes I've made or handle them yourself. Appreciate your work here and want to ensure you are acknowledged for your effort.

@AaronRobinsonMSFT AaronRobinsonMSFT added the needs-author-action An issue or pull request that requires more info or actions from the author. label Mar 2, 2026
@pedrobsaila
Copy link
Contributor Author

Hey @AaronRobinsonMSFT yes you can fold in your changes, no worries about that.

@dotnet-policy-service dotnet-policy-service bot removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Mar 3, 2026
@AaronRobinsonMSFT
Copy link
Member

Hey @AaronRobinsonMSFT yes you can fold in your changes, no worries about that.

@pedrobsaila I don't think I can push to your branch. I can create a PR from my branch or you can cherry-pick my changes, up to you.

@AaronRobinsonMSFT
Copy link
Member

/ba-g Known issues.

Issues fixed in #125051

@AaronRobinsonMSFT
Copy link
Member

@MichalStrehovsky Please take another look at this. I've narrowed the scenario considerably.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Reflection community-contribution Indicates that the PR has been added by a community member linkable-framework Issues associated with delivering a linker friendly framework

Projects

Status: No status

4 participants