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

thinkin.arbys's Avatar

thinkin.arbys

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

    Hello,

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

    (internal issue #16170)

    Best regards,
    Daniel

  2. Support Staff 2 Posted by PostSharp Techn... on 27 Jun, 2018 04:34 PM

    PostSharp Technologies's Avatar

    Hello,

    We're closing the ticket for now as the bug has been internally filed as issue #14219. We will contact you as soon as the bug fix has been released.

    For more details on our support policies and prioritization of bug fixes, please visit https://www.postsharp.net/support/policies

    PostSharp Team

  3. PostSharp Technologies closed this discussion on 27 Jun, 2018 04:34 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? 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