NotSupportedException when ValidateGroupNotEmpty attribute is used in ActiveRecord class

13 views
Skip to first unread message

Bogdan Rogalski

unread,
Jan 13, 2010, 1:02:56 PM1/13/10
to castle-pro...@googlegroups.com
Hi,

when I use the 'ValidateGroupNotEmpty' attribute on a ActiveRecord
class I get this exception:

System.NotSupportedException: You must call Build with a type parameter

That's how my attribute looks like:

[ValidateGroupNotEmpty("ProductOrTeam", "Select Product or Team")]
[BelongsTo("ProductId",NotNull=false)]
public Product Product
{
get { return product; }
set { product = value; }
}


The exception is not thrown when I use it in my model view class that
is not an ActiveRecord class.

Any ideas how I can get ValidateGroupNotEmpty attribute to work on my
ActiveRecord classes as well?

Thanks,
Bogdan Rogalski

error source:
ActiveRecordStarter.Initialize(Assembly.Load("ProductWarehouse.Core"),
ActiveRecordSectionHandler.Instance);

here is the partial stack trace:
[NotSupportedException: You must call Build with a type parameter]
Castle.Components.Validator.ValidateGroupNotEmptyAttribute.Build() +82
Castle.ActiveRecord.Framework.Internal.ActiveRecordModelBuilder.ProcessProperties(Type
type, ActiveRecordModel model) +589
Castle.ActiveRecord.Framework.Internal.ActiveRecordModelBuilder.PopulateModel(ActiveRecordModel
model, Type type) +168
Castle.ActiveRecord.Framework.Internal.ActiveRecordModelBuilder.Create(Type
type) +255

G. Richard Bellamy

unread,
Jan 13, 2010, 6:15:30 PM1/13/10
to castle-pro...@googlegroups.com
Markus,

Is there a particular reason ActiveRecordModelBuilder is adding validators
to the model, when those validators aren't then used during validation? The
reason I ask is that it's calling the Build() method of the
AbstractValidationAttribute, and that's what's throwing this exception. The
ValidateGroupNotEmpty attribute requires an instance, and Build() has no
access to that, and neither would ActiveRecordModelBuilder.

Does the model builder ever need to concern itself with Validation
attributes? IIRC, NH Validation is a consumer of the model mappings, rather
than a part of the generation of those mappings, so it doesn't participate
in the mapping process either.

Let me know if I'm way off base here.

-rb

G. Richard Bellamy

unread,
Jan 15, 2010, 4:15:24 PM1/15/10
to G. Richard Bellamy, castle-pro...@googlegroups.com
Markus,

I know you've been busy with the release. Have you had a chance to think
about this?

I have an edit to make my question more clear:

"Can you think of a reason ActiveRecordModelBuilder is adding validators to
the model, when the model's validators collection isn't used during
validation?"

-rb

Markus Zywitza

unread,
Jan 18, 2010, 3:19:27 AM1/18/10
to castle-pro...@googlegroups.com
Sorry, I've been offline over the weekend. I don't know why AR is
adding Validators, I think it's a remnant of the time when Validation
was part of AR. Perhaps we just remove that part and see whether the
tests still pass.

-Markus

2010/1/15 G. Richard Bellamy <rbel...@pteradigm.com>:

> --
> You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
> To post to this group, send email to castle-pro...@googlegroups.com.
> To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.
>
>
>
>

Reply all
Reply to author
Forward
0 new messages