Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 621249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:51:13+00:00 2026-05-13T18:51:13+00:00

I have set up a ruleset in my configuration file which has two validators,

  • 0

I have set up a ruleset in my configuration file which has two validators, one of which is a built-in NotNullValidator, the other of which is a custom validator. The problem is that I see the NotNullValidator hit, but not my custom validator.

The custom validator is being used to validate an Entity Framework entity object.

I have used the debugger to confirm the NotNull is hit (I forced a failure condition so I saw it set an invalid result), but it never steps into the custom one.

I am using MVC as the web app, so I defined the ruleset in a config file at that layer, but my custom validator is defined in another project. However, I wouldn’t have thought that to be a problem because when I use the Enterprise Library Configuration tool inside Visual Studio 2008 it is able to set the type properly for the custom validator. As well, I believe the custom validator is fine as it builds ok, and the config tool can reference it properly.

Does anybody have any ideas what the problem could be, or even what to do/try to debug further?

Here is a stripped down version of my custom validator:

[ConfigurationElementType(typeof(CustomValidatorData))]
public sealed class UserAccountValidator : Validator
{
    public UserAccountValidator(NameValueCollection attributes)
        : base(string.Empty, "User Account")
    {
    }

    protected override string DefaultMessageTemplate
    {
        get { throw new NotImplementedException(); }
    }

    protected override void DoValidate(object objectToValidate,
        object currentTarget, string key, ValidationResults results)
    {

        if (!currentTarget.GetType().Equals(typeof(UserAccount)))
        {
            throw new Exception();
        }

        UserAccount userAccountToValidate = (UserAccount)currentTarget;

        // snipped code ...

        this.LogValidationResult(results,
            "The User Account is invalid", currentTarget, key);
    }
}

Here is the XML of my ruleset in Validation.config (the NotNull rule is only there to force a failure so I could see it getting hit, and it does):

<validation>
<type defaultRuleset="default" assemblyName="MyProj.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
  name="MyProj.Entities.UserAccount">
  <ruleset name="default">
    <properties>
      <property name="HashedPassword">
        <validator negated="true" messageTemplate="" messageTemplateResourceName=""
          messageTemplateResourceType="" tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.NotNullValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          name="Not Null Validator" />
      </property>
      <property name="Property">
        <validator messageTemplate="" messageTemplateResourceName=""
          messageTemplateResourceType="" tag="" type="MyProj.Entities.UserAccountValidator, MyProj.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
          name="Custom Validator" />
      </property>
    </properties>
  </ruleset>
</type>
</validation>

And here is the stripped down version of the way I invoke the validation:

                var type = entity.GetType()
                var validator = ValidationFactory.CreateValidator(type, "default", new FileConfigurationSource("Validation.config"))
                var results = validator.Validate(entity)

Any advice would be much appreciated!

Thanks,

Chris

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:51:14+00:00Added an answer on May 13, 2026 at 6:51 pm

    You custom validator should not be configured as a “property validator”, but as a “self validator”. Move the node up to directly under the node in your configuration. That should do the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set up transactional replication between two SQL Servers on different ends of
I have a WordPress site (2.6.2) in which I have set the Home page
We have set up a system where notifications get sent to a user with
I have set a canvas' background to an image of a company logo. I
I have set up a version control system using TortoiseSVN at my home to
I have set up a Django application that uses images. I think I have
I have set the FlushMode property on an NHibernate session to FlushMode.Never, but when
I have set the itemRollOver and itemRollOut event listeners on a List component, but
I have set of scripts for doing scripted installs. You can use the scripts
I have set a list of items in a combobox, but when I debug

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.