In my VS.Net C# project I have about 10 custom attributes classes. For the longest time there wasn't a problem. Then once in a while I would get this error: Attribute '(custom attribute class)' is not valid on this declaration type. It is valid on '' declarations
only. I put up with this occasional error message simply because I didn't feel like writing this here e-mail. Well, today it finally blew up. I can't compile, despite my many efforts to correct the problem. These decalarations cannot be removed, and shouldn't
even really be commented out. The question is: has anyone gotten or heard of this problem, and how can it be remedied? Please keep in mind that it came occasionally but would always eventually compile (until now).
I have found the problem. I always feel like an ass writing a post and answering it myself. Well, I was tired so get off my case! Soon after I wrote that message I realized that the errors were all from my attribute classes that inherited a .Net derived attribute.
For example, this class generated errors: class InstructionsAttribute: DescriptionAttribute I inherited the DescriptionAttribute just to avoid creating the Description member (bad practice, I know). But when I changed it to just inherit Attribute instead of
DescriptionAttribute, the error disappeared. Not sure if there is a moral of this story, other than "Don't derive .Net native derived attributes." You know you want to try saying that 10 times fast...
None
0 Points
26 Posts
For the pros - Custom Attribute Declaration Problem
Sep 30, 2003 04:54 PM|themastuh|LINK
None
0 Points
26 Posts
Re: For the pros - Custom Attribute Declaration Problem
Oct 01, 2003 08:51 AM|themastuh|LINK