locked
Constructor on type 'USStateValidator" not found. RRS feed

  • Question

  • User-40703516 posted

    I downloaded the Validation Application Block and I am attempting to use the already written USStateValidator that is provided with the ValidationAspNetQuickStart.

     I added the following to the ValidationQuickStart.BusinessEntities.dll.config file under "Address", "RuleSetB".

    <property name="State">
                <validator messageTemplate="Site State: Must be a valid two-digit US state designation." messageTemplateResourceName=""
                  messageTemplateResourceType="" tag="" type="ValidationQuickStart.CustomValidators.USStateValidator, ValidationQuickStart.CustomValidators, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                  name="USStateValidator" />
              </property>  


    When I attempt to validate the form in the test application using "RulesetB", it gives me the followin error: "Constructor on type "ValidationQuickStart.CustomValidators.USStateValidator" not found."

    Here is the code for the validator as provided by Microsoft (I have made no changes to it):

    namespace ValidationQuickStart.CustomValidators
    {
        [ConfigurationElementType(typeof(CustomValidatorData))]
        public class USStateValidator : DomainValidator<string>
        {
            private static List<string> stateCodes = new List<string>(new string[] {
                "AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL",
                "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH",
                "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM",
                "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC",
                "SD", "TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY"});
    
            public USStateValidator()
                : base(stateCodes)
            {
            }
    
            protected override string DefaultNonNegatedMessageTemplate
            {
                get { return "The supplied code does not represent a valid US State"; }
            }
    
        }
    }


    The USStateValidator appears to work normally when using "RulesetA" which uses only attributes on the BusinessEntity class.

    Here is the example from the business entity class that works just fine:

    [USStateValidator(Ruleset = "RuleSetA")] 
            public string State
            {
                get { return state; }
                set { state = value; }
            }


     

    Does anyone know what is wrong with this?  I need to get this validator working using the xml file instead of declaring on the actual class itself.

    Friday, October 16, 2009 1:13 PM

Answers

  • User-40703516 posted
    Well, found the problem.
     
    I'm not sure why the validator works when called using the Attributes on a class, but in order to fix this I had to add a constructor to the validator class that took a "NameValueCollection" as a parameter.
     
    So I added the following lines to the USStateValidator.cs class:
     
    public USStateValidator(NameValueCollection myCollection)
                : base(stateCodes)
            {
            }

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 19, 2009 9:08 AM

All replies

  • User-40703516 posted

    No ideas? 

    Monday, October 19, 2009 8:38 AM
  • User-40703516 posted
    Well, found the problem.
     
    I'm not sure why the validator works when called using the Attributes on a class, but in order to fix this I had to add a constructor to the validator class that took a "NameValueCollection" as a parameter.
     
    So I added the following lines to the USStateValidator.cs class:
     
    public USStateValidator(NameValueCollection myCollection)
                : base(stateCodes)
            {
            }

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 19, 2009 9:08 AM