The reason you see the error is because ToString() is a method, and therefore the value cannot be computed at compile time.
If you can use [RequiresRole (HardCodedRoles.Managers)], you can execute ToString elsewhere in your code, and this can give you the necessary functionality. This will require changing the parameter of your attribute from string to HardCodedRoles .
(I would suggest that using const will not work, because the type of the parameter will be string , so the input will not be limited.)
source share