Why Compiler Error CS0416 exist? #7252
Replies: 2 comments
-
This is probably because the type information has to be encoded somehow to be stored in the assembly, and there are technical reasons why encoding a generic argument type is difficult or impossible. There was a discussion about this a few months ago (no way I can find it now); there is a feasible way to make this work, but it requires some heavy lifting WRT both runtime and language changes, and I don't think it's high priority enough to work on right now. |
Beta Was this translation helpful? Give feedback.
-
Attributes are stored as constants in assembly, so it is impossible to use a type parameter that cannot be resolved at compile time. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
ITNOA
as you see in https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0416
'type parameter': an attribute argument cannot use type parameters
A type parameter was used as an attribute argument, which is not allowed. Use a non-generic type.
The following sample generates CS0416:
My question is, why we cannot pass typeof generic type to attribute?
thanks
Beta Was this translation helpful? Give feedback.
All reactions