-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Cannot reflect on generic attributes whose constructors original definition uses type parameters #56492
Comments
This looks like a bug in coreclr (and possibly mono). Could you provide a test written in IL to cover the scenario? The snippet above doesn't include the Attr type. Also, please identify if this C# feature is expected to be enabled in the .NET 6 timeframe, or if this is a post-.NET 6 request. |
This bug was fixed in dotnet/coreclr#25054 an there is test for it |
@RikkiGibson please verify that your issue still reproduces on some version of .NET 5 or 6. The change @AviAvni references should have fixed it in those versions. |
I ran the test again and verified that the value of I also dumped the IL. Unfortunately the compiler I'm using is built from source, otherwise it would be a bit easier to give you a source reproducer: IL dump
In case it helps I am also attaching a zip file with the project. You won't be able to build it because it depends on a local compiler, but you should be able to run it with e.g. |
We would like to ship the feature in the .NET 6 timeframe if possible. |
@davidwrighton Please let me know if there's anything I can do to help drive this. |
@RikkiGibson, this is on my radar, and I expect to get it fixed before RC1. I'm currently looking at some stress issues, and then I'll take a look at this one. |
* Fix CustomAttributeData in the presence of generic attributes - Generic attributes need to force the actual exact method to be loaded not just the canonical scenario - GenericAttribute testing had been disabled due to dotnet/msbuild#6734 - Move GenericAttribute test project to Pri0 as its the only generic custom attribute runtime testing that will occur before .NET 6.0 ships - Test disabled on Mono as Mono currently doesn't support this feature. Fixes #56492
Thank you so much for the fix @davidwrighton! |
Related to dotnet/roslyn#55190
The following program throws
CustomAttributeFormatException
(using the generic-attributes feature compiler):Importantly, if we change the constructor parameter type to
string
, we don't get an exception. It's also worth noting that if we declare a property of a type parameter type, then specify a value for it at the usage of the attribute, we decode it just fine.The compiler produces this IL for the type
Program
:§II.21 Custom attributes in ECMA 335 reads:
It seems like for the feature "generic attributes" to work properly it is necessary for the Ctor item to represent a method reference rather than a method declaration, because the method in question could be contained in a constructed type. However, I am not sure I comprehend the finer points of the spec here.
Actually, I am not sure if what I am observing is a compiler bug, or a coreclr bug, or a spec issue. Poking around the compiler's emit of the attribute constructor, it does seem to be simply producing a reference to the constructed method symbol.
cc @jkotas @AviAvni
The text was updated successfully, but these errors were encountered: