is not an attribute class

Topics: Validation Application Block
Feb 14, 2011 at 10:20 PM

I was trying to create a cutomer class as follows, however i am geting  the following errors

'Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RegexValidator' is not an attribute class
'Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RegexValidatorAttribute' is not an attribute class
'Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator' is not an attribute class
'Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator' is not an attribute class
'Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator' is not an attribute class
'Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidatorAttribute' is not an attribute class
'Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidatorAttribute' is not an attribute class
'Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidatorAttribute' is not an attribute class

I am using enterprise library 5.0 and on visual studio 2010 ultimate, any idea

 


using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

 

namespace Architecture_2010_Sample.Common.Entities
{
    public class Customer
    {
        private int _customerId;
        private string _firstname;
        private string _lastname;
        private string _emailAddress;

        public int CustomerId
        {
            get { return _customerId; }
            set { _customerId = value; }
        }

        [StringLengthValidator(1, 50, MessageTemplate = "Firstname must be between {3}-{5} characters.")]
      
 public string Firstname
        {
            get { return _firstname; }
            set { _firstname = value; }
        }

        [StringLengthValidator(1, 50, MessageTemplate = "Lastname must be between {3}-{5} characters.")]
        public string Lastname
        {
            get { return _lastname; }
            set { _lastname = value; }
        }

        [StringLengthValidator(1, 100, MessageTemplate = "EmailAddress must be between {3}-{5} characters.")]
        [RegexValidator(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", MessageTemplate = "Invalid EmailAddress.")]
        public string EmailAddress
        {
            get { return _emailAddress; }
            set { _emailAddress = value; }
        }
    }
}

Feb 15, 2011 at 2:58 AM

Have you add reference to System.ComponentModel.DataAnnotations assembly to your project?

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Mar 4, 2011 at 8:41 AM

Thanks Gino,

I was on vacation so never replied to these on time how ever ths solution has worked for me. I am trying to rewrite the sample of Hayden-WCSFExample to work on MS2010 and i guess as expected i am getting an error here and there.

Here is another one

 

The type or namespace name 'ValidationCallHandlerAttribute' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'ValidationCallHandler' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'CachingCallHandlerAttribute' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'CachingCallHandler' could not be found (are you missing a using directive or an assembly reference?)

 

Sample code

  

using System.Collections.Generic;


using Microsoft.Practices.EnterpriseLibrary.Validation;


using Architecture_2010_Sample.Common.Entities;

 

 

namespace Architecture_2010_Sample.Common.Services
{
    public interface ICustomerDAO
    {
        Customer GetCustomerByCustomerId(int customerId);
     
        [CachingCallHandler(0, 0, 15)]
        List<Customer> GetAllCustomers();

        [ValidationCallHandler]
        void InsertCustomer(Customer customer);

        [ValidationCallHandler]
        void UpdateCustomer(Customer customer);

        void DeleteCustomer(int customerId);
    }
}

I tried to include librarries from both of the following libraries with no avail.  HELP! Cheers

 

 EntLibContrib.PolicyInjection
Microsoft.Practices.EnterpriseLibrary.PolicyInjection

Mar 4, 2011 at 12:48 PM

You need to add reference to Microsoft.Practices.Unity.Interception.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Mar 7, 2011 at 10:14 AM

It did not work for me

I read on the Enterprise Library 5.0 documentation the following which i tried but did not work. The Aim is to make  CachingCallHandler and the ValidationCallHandler to work . but it is still asking for the type or namespace name. I am a bit confused...

The Caching handler is no longer included in Enterprise Library due to concerns around the issues of cache contamination and other limitations previously documented. If you require the Caching handler, you can download the previous version from the Enterprise Library community Web site at http://www.codeplex.com/entlib/ and integrate it with Enterprise Library.

 

Mar 7, 2011 at 10:45 AM

Oops, sorry, I guess I confused it with what used to be in 4.1 version.  If you want the ValidationCallHandler, you need to add reference to the Validation assembly.  And unfortunately, yes, the CachingCallHandler is no longer included in version 5.0 so you would have to get its source code from the previous version and modify it so that it's compatible with version 5.0.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com