Exclusion attributes with parameters are ignored by dotCover

If I set up an exclusion filter for, let's say System.ObsoleteAttribute, then it works OK for items marked with [Obsolete], but not for items marked with [Obsolete("Message")]. It appears that dotCover ignores any attributes which take a parameter. This is a bit of a pain because I want to be able to automatically exclude code contracts classes marked with System.Diagnostics.Contracts.ContractClassFor attribut (which takes as System.Type as a parameter) without having to add extra attributes, but it doesn't work.


Hello Clive,

I've investigated your issue and it seems that the problem exists only for the System.Diagnostics.Contracts attributes and isn't related to attribute parameters. Filtering by any other attribute (including System.ObsoleteAttribute) works fine for me, independently whether an attribute takes parameters or not.

Regarding the System.Diagnostics.Contracts attributes, the problem is that many of these attributes are conditional. If CONTRACTS_FULL symbol is not defined for your project, such attributes as ContractClassFor, ContractInvariantMethod etc. are stripped out of your code at compile-time. As dotCover performs a run-time code analysis, it doesn't know anything about stripped out attributes and so can't filter out corresponding classes. In this case you can use filtering by class names (e.g. *Contract) instead of attribute filtering.

If "Runtime Contract Checking" is turned on for your project, CONTRACTS_FULL symbol is defined automatically. But in this case, I think, you don't need to filter out contract classes because they will be removed from the compiled code by the Code Contracts binary rewriter and won't be included in the coverage report (though the corresponding code will still be highlighted in VS because the binary rewriter includes it to the class, which this contract belongs to).

Please, let me know if you'll have any questions. Regards.


Thanks Ekaterina, that explains it. I don't understand why I had a problem using [Obsolete("Message")] instead of [Obsolete] as I can't reproduce it now - I must have been doing something wrong.


Please sign in to leave a comment.