-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Mono does not support querying for and open generic type when searching for Attributes #56887
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: Issue DetailsDescriptionWhile fixing issue #56492 in coreclr, I discovered that the generic attribute test was not running on any platform. When I enabled it, not only did mono have issue #56492, it also didn't appear to support generic attribute at all. This may be a blocker for dotnet/roslyn#55190. As part of the fix for the coreclr bug, in PR #56879 I will be fixing the build of the generic attribute test, but disabling it on mono platforms. @RikkiGibson, please comment on this issue and its importance.
|
@lambdageek @vargaz fyi |
The test fails at this line: because it calls Array.CreateInstance () with the open generic type. |
Ah, if its just the issue around the open type... see |
I do agree though, where is the null coming from? That just seems odd. I'll take a look at the coreclr behavior, and try and figure out what is supposed to trigger that to happen.. |
Ah. The null comes from
object[] into an Attribute[] or null. I can't explain why anyone would write the code this way, but that's where the null comes from.
|
Speculatively I think the compiler sees a few options from our POV:
Feel free to correct me here @jcouv @jaredpar if these options don't seem right. |
@RikkiGibson I've spent a bit of time looking into the issue (and figuring out how to run the tests under Mono), and I can say that while the Generic Attributes test as written fails, it ONLY fails for the case of attempting to look up an attribute of an open type. As that particular query could exist outside of any actual usage of generic attributes I believe it is irrelevant to general generic attribute support. As such, I think that there is no risk to the C# feature at this time even if this particular issue isn't fixed in Mono, and that I'd like @vargaz/@lambdageek to determine what priority/approach they wish to take on fixing the remaining issue identified via this test. |
Is the GetCustomAttribute () call supposed to return null for an open type ? According to the docs, it should return a (possible empty) array, or throw an exception. |
Well that's a good question. I'd like to defer to @steveharter for what should this thing be doing, and then lets make the two runtimes implement the same logic. I'm generally of the opinion that the particular scenario we're talking about here is probably just wrong. |
Just to confirm, that means in a case of: public sealed MyGenericAttribute<T> : NonGenericBaseAttribute { } asking I might be biased, but I'm under the impression that's going to be the majority case. Of course, if Mono can fix the problematic case in time, that's all the better, but maybe it doesn't need to be a full blocker. |
If we want to make GetCustomAttributes () work with an open type, then it needs to return an object[], since the return array needs to contain different instantiations of the same type. |
I don't think we have any consensus on what the behavior should be for anything involving open generics and the GetCustomAttributes api. Obviously we can't return an array of open types. I'm not entirely comfortable with just returning null as CoreCLR does, and I'm pretty sure an exception around bad array type creation isn't what should happen either. Also we can't change the signature of any public apis. That is why I pinged @steveharter because he's nominally in charge of reflection, and might be able to provide a more reasoned opinion on what should happen. However as this is a fairly edge case, I'm ok with shipping what we do have. However, if we decide to do that, I'd like to know so I can modify the existing coreclr runtime test to get rid of the current tests around open generics and re--enable it for mono, as we don't have any coverage for generic attributes in mono at all right now. |
Doesn't it already return |
Returning Attribute[] could work. |
Is there any work to be done here for 6.0 ? |
No, we'll deal with this in 7.0. I quite like the idea of consolidating on the idea that a request for the open type yields an Attribute[] filled with the closed instances that are actually on the metadata object, but I don't think that will happen now. Also, from some internal discussion about the thicket of runtime/metadata problems that have been identified it looks like the C# feature will be pushed into preview, so we can both get the code out there, and fix the rest of the ecosystem before we make this a fully supported C# feature. |
Also related: #64169 |
@davidwrighton @vargaz - do we need any work towards this for 7.0 ? Want to make sure we have enough time for that if needed. |
Moving to 8.0.0 for any new Mono support needed. |
Can this issue be now closed? |
Fixed in #78091. |
Description
While fixing issue #56492 in coreclr, I discovered that the generic attribute test was not running on any platform. When I enabled it, not only did mono have issue #56492, it also didn't appear to support generic attribute at all. This may be a blocker for dotnet/roslyn#55190. As part of the fix for the coreclr bug, in PR #56879 I will be fixing the build of the generic attribute test, but disabling it on mono platforms.
@RikkiGibson, please comment on this issue and its importance.
@AlekseyTs, fyi, please make sure the right person in mono is aware of this.
The text was updated successfully, but these errors were encountered: