Skip to content
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

Comment in Attribute.cs is not correct #35784

Closed
leotsarev opened this issue May 4, 2020 · 2 comments · Fixed by #111225
Closed

Comment in Attribute.cs is not correct #35784

leotsarev opened this issue May 4, 2020 · 2 comments · Fixed by #111225
Labels
area-System.Runtime backlog-cleanup-candidate An inactive issue that has been marked for automated closure. bug in-pr There is an active PR which will close this issue when it is merged no-recent-activity
Milestone

Comments

@leotsarev
Copy link
Contributor

https://github.com/dotnet/coreclr/blob/a9f3fc16483eecfc47fb79c362811d870be02249/src/System.Private.CoreLib/shared/System/Attribute.cs#L122

// An object of type Attribute will cause a stack overflow.
// However, this should never happen because custom attributes cannot contain values other than
// constants, single-dimensional arrays and typeof expressions.

Actually, Attributes could contain everything, they just can't receive values other than... from constructor parameters.
I.e. consider following code (perfectly working in ASP.NET Core 2.1, but broke Api Explorer on 3.1)

public class MyAuthorize : TypeFilterAttribute
    {
        public Permission Permission { get; set; }
        public bool AllowPublish { get; set;
        public bool AllowAdmin { get; set; }

        public MyAuthorize(Permission permission = Permission.None)
            :base (typeof(MyAuthorizeFilterImpl))
        {
            Arguments = new[] { this };
        }
        private class MyAuthorizeFilterImpl: IAsyncAuthorizationFilter
        {
            public MasterAuthorizeFilterImpl(MyAuthorizeFilterImpl self, IAuthorizationService authorization)
            {
                Permission = self.Permission;
                AllowAdmin = self.AllowAdmin;
                AllowPublish = self.AllowPublish;
                Authorization = authorization;
            }

Suggestions:

  • throw InvalidOperationException instead of Debug.Assert
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Runtime untriaged New issue has not been triaged by the area owner labels May 4, 2020
@joperezr joperezr added bug and removed untriaged New issue has not been triaged by the area owner labels Jul 7, 2020
@joperezr joperezr added this to the Future milestone Jul 7, 2020
@joperezr
Copy link
Member

joperezr commented Jul 7, 2020

cc: @stephentoub

Copy link
Contributor

Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

This process is part of our issue cleanup automation.

@dotnet-policy-service dotnet-policy-service bot added backlog-cleanup-candidate An inactive issue that has been marked for automated closure. no-recent-activity labels Jan 7, 2025
@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Runtime backlog-cleanup-candidate An inactive issue that has been marked for automated closure. bug in-pr There is an active PR which will close this issue when it is merged no-recent-activity
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants