Cannot use [NotEmptyAttribute] on generic ICollection<T> interface (not class)

thinkin.arbys's Avatar


13 Jun, 2018 09:25 PM

When specifying [NotEmpty] on a method parameter that is a generic interface, I'm having the same issue described here. I'm using PostSharp.Patterns.Common.dll v5.0.51.0 and C# 7.1.

My function signature is

void MyMethod([NotEmpty] ICollection<string> strings)

It's throwing a compilation error:

MyProject.MyClass.MyMethod(System.Collections.Generic.ICollection<System.String>)@strings is of type System.Collections.Generic.ICollection`1<T><string> which can not be matched to any ValidateValue method of aspect PostSharp.Patterns.Contracts.NotEmptyAttribute.

The issue appears to be that the type is a generic interface. If I change it to a class such as List<string>, it compiles fine. I also tested that ICollection works, and a ICollection<T> field/property (rather than a method parameter) does not work.

This is most likely because ICollection<T> does not inherit ICollection, while List<T> and other generic enumerables do.

  1. Support Staff 1 Posted by PostSharp Techn... on 14 Jun, 2018 09:52 AM

    PostSharp Technologies's Avatar


    thanks for reporting the issue. We will be working on a fix.

    (internal issue #16170)

    Best regards,

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac