[NotEmpty] should not throw ArgumentNullException for empty strings/collections

alexander.jesner's Avatar


03 Jun, 2015 02:35 PM

The current implementation (4.1.13) of the [NotEmpty] attribute for strings/collection throws an ArgumentNullException if the string/collection has a size of 0 characters/elements.

I think the correct exception would be an ArgumentException.

Is this a bug?

Here is a unit test to reproduce the issue:

        public void TestNotEmptyAttribute()
            Assert.Throws<ArgumentNullException>(() => TestEmptyString(null));
            Assert.Throws<ArgumentException>(() => TestEmptyString(string.Empty));

        public void TestEmptyString([NotEmpty] string a)

  1. Support Staff 1 Posted by PostSharp Techn... on 04 Jun, 2015 07:36 AM

    PostSharp Technologies's Avatar


    thank you very much for reporting this.

    The fix would be a breaking change. We need to investigate what can be done in this case and we will contact you when we know more.

    Internally filed as #11538.


  2. Support Staff 2 Posted by PostSharp Techn... on 08 Jun, 2015 09:30 AM

    PostSharp Technologies's Avatar


    I'm sorry, we are not going to fix it. This behavior could be perceived as anti-intuitive but it is working as designed. In addition to that it would be a breaking change.

    We created a freature request on our UserVoice. You are welcome to upvote the request.


  3. System closed this discussion on 13 Apr, 2016 10:33 AM.

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

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