[IgnoreNull] or [ValidationComposition] throws exception while adding objects to list

Topics: Validation Application Block
Oct 18, 2011 at 9:37 PM

I have a class Partner and I use entlib5 validation block to validate class's fields (using data anottations). In one of method I read db table and create binding list of Partner's objects, but if there is an [IgnoreNull] annotation or [ValidationComposition]+[NotNullValidator] i get an System.NotSupportedException (for example: A validation attribute of type ValidatorCompositionAttribute cannot be used to validate values.)

If I use only [StringLengthValidator] there isn't any exception (but there is another issue: if I use StringLengthValidator without IgnoreNulls or similar, and specify only string upper bound this field is automatic invalid - I must press space and then backspace in some textbox to pass validation)

What is a problem?

Oct 20, 2011 at 7:00 AM

Davor, is this an MVC application using CompositionType.Or?  If so then DataAnnotations doesn't support Or composition.  

See http://entlib.codeplex.com/discussions/211051.



Oct 20, 2011 at 7:49 AM
Edited Oct 20, 2011 at 1:39 PM

It's a MVVM WPF application (business entities are in separeted project). I get the same error (only when adding values to object's fields, databinding works) for IgnoreNull :S

Composition.And and IgnoreNulls is also NotSupported

Oct 21, 2011 at 2:35 AM

Did you solve your issue?


-- Randy

Oct 21, 2011 at 5:12 PM
Edited Oct 21, 2011 at 5:16 PM

Sorry, forgot to reply with my "solution".

Unfortunately, I didn't managed to validate field using Compostion.Or + NotNull or IgnoreNulls (this validators works for me only when I bind data from WPF to business logic class).

What I did is to set private field like this:

private string _address = string.Empty;

[StringLengthValidator(30, "Max. 30 chars")]

public string Address {

get { return _address; }

set { _address = value; }


Now, in first call field _address is not null, it's empty string and IgnoreNulls annotation is now not needed. StringLengthValidator now checks only if Address is <=30 characters.