| Severity | Error |
| Reported by | PostSharp |
| Message | Maximal number of errors reached: <ErrorCount>. |
Cause
PostSharp counts the errors that it reports while it builds a project. PostSharp reports PS0016 when this count reaches 500, which is a fixed limit. <ErrorCount> is the number of errors reported so far.
So many errors rarely come from 500 different mistakes. Usually, one mistake causes the same error on many declarations, for example:
- An aspect is multicast to too many declarations, with an assembly-level attribute, a
postsharp.configfile or a wildcard inAttributeTargetTypes, and its compile-time validation rejects most of them. - An architecture constraint is applied to a whole namespace or assembly, and many usages violate it.
- A reference of the project is missing or has the wrong version, and PostSharp cannot resolve many of the types that the aspects use.
This message requires a build that reports 500 other errors, so no example can show it.
Resolution
- Look at the first errors of the build, not at PS0016. Fix the cause that they share, then build again.
- When an aspect is applied to too many declarations, restrict its multicasting with the properties of MulticastAttribute, such as AttributeTargetTypes and AttributeTargetMemberAttributes, or exclude declarations with AttributeExclude. See Adding Aspects to Multiple Declarations Using Attributes.
- When the errors come from a validation of your own aspect, make the aspect skip the declarations that it does not support, for example by returning
falsefromCompileTimeValidatewithout reporting an error.
See Also
Reference
Other Resources