Validation Application block Error

Topics: Validation Application Block
Mar 31, 2009 at 8:16 PM
Hi,

I have a solution with a project that has the data objects and another one with the webApp.

When i adapted the validation code existing in the validationAspNetQuickStart i get the following error:

Method 'CreateObject' in type 'Microsoft.Practices.EnterpriseLibrary.Validation.Instrumentation.ValidationInstrumentationListenerCustomFactory' from assembly 'Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

Can you please tell me what's missing?

The code is simple:

using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

Object Class
namespace WSSCD_DataStructures
{
    public class Request
    {
         private string codigoENT;

         [StringLengthValidator(1, 20, Ruleset = "RuleSetA", MessageTemplate = "RuleSetA - First Name must be between 1 and 20 characters")]
        public string CodigoENT
        {
            get { return codigoENT; }
            set { codigoENT = value; }
        }
    }
}

in the aspx code behind:

protected void Page_Load(object sender, EventArgs e)
    {
        // Set the ruleset for every validator control
        foreach (IValidator v in this.GetValidators(null))
        {
            if (v is PropertyProxyValidator)
            {
                PropertyProxyValidator validator = v as PropertyProxyValidator;
                validator.RulesetName = "RuleSetA";
            }
        }
    }

    protected void submitButton_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            validationResultsLabel.Text = "Data is valid.";
            // Now you would create the objects and process them
        }
        else
        {
            validationResultsLabel.Text = "Data is invalid.";
        }
    }


Xml File with the validation rules:
<configuration>
 
  <configSections>
    <section name="validation" type="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationSettings, Microsoft.Practices.EnterpriseLibrary.Validation" />
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" />
  </configSections>
 
  <validation>
    
    <type assemblyName="WSSCD-DataStructures, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="WSSCD_DataStructures.Request">
      
      <ruleset name="RuleSetA">
        
        <properties>
          
          <property name="CodigoENT">
            <validator lowerBound="3" lowerBoundType="Inclusive" upperBound="3"
              upperBoundType="Inclusive" negated="false" messageTemplate="O código da Entidade deve ser composto por três caracteres."
              messageTemplateResourceName="" messageTemplateResourceType=""
              tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation"
              name="String Length Validator" />
          </property>
          
        </properties>
        
      </ruleset>

      <ruleset name="RuleSetB">
        
        <property name="CodigoENT">
          <validator lowerBound="5" lowerBoundType="Inclusive" upperBound="5"
            upperBoundType="Inclusive" negated="false" messageTemplate="O código da Entidade deve ser composto por cinco caracteres."
            messageTemplateResourceName="" messageTemplateResourceType=""
            tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation"
            name="String Length Validator" />
        </property>
        
      </ruleset>
      
    </type>
    
  </validation>
 
</configuration>

Web.config File

<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common"/>

    <enterpriseLibrary.ConfigurationSource selectedSource="File Configuration Source">
        <sources>
            <add name="File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common" filePath="..\WSSCD - DataStructures\WSSCD-DataStructures.dll.config"/>
        </sources>
    </enterpriseLibrary.ConfigurationSource>

Best Regards,
Manuel
Apr 1, 2009 at 10:33 AM
Could you check if the WSSCD-DataStructures.dll.config still has the validation section?  I just want to make sure that the sections defined in it didn't get cleared when you used it as a File Configuration Source.  And make sure it's the correct file path.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 2, 2009 at 11:32 PM
Hi,

Yes it had. I've figured out what's wrong...I was using Ent. Library 4.0 in a project with 2.0 framework version.

Thank's
Manuel
Apr 3, 2009 at 8:37 AM
Ah, I see.  Glad you've already find out what's causing the error.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Feb 26, 2010 at 5:15 PM

Hello,

I have this same exact error, however I am using Ent. Libary 4.1 with 3.5 framework. What can I do to fix this issue some that I am not getting the following anymore.

Method 'CreateObject' in type 'Microsoft.Practices.EnterpriseLibrary.Validation.Instrumentation.ValidationInstrumentationListenerCustomFactory' from assembly 'Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

Any help would be appreciated, thanks.

Feb 27, 2010 at 5:23 AM

Are you using Entlib 4.0 or 4.1? You said 4.1, but the version # in the error message is 4.0. If you're mixing them that could cause all sorts of weird errors.

 

 

Feb 27, 2010 at 9:22 PM

I simply copied and pasted the error from above is all. The error I am getting is the same, however the version 4.1.

Mar 1, 2010 at 2:39 AM

But do you have 2 versions of entlib installed on your machine. 

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com

Mar 1, 2010 at 1:23 PM

No. I only have the 4.1 version installed on my machine.

Mar 1, 2010 at 2:04 PM

Hi,

This is weird. Anyways, just wanna ask does your project used the previous version of ent lib and then just switch to ent lib 4.1 ? or your machine has a previous version of ent lib and you've just uninstalled?

Valiant Dudan
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Mar 1, 2010 at 3:06 PM

There are no previous versions of the ent libraries on my machine. The only version installed is 4.1 and the only version used in my projects is 4.1.

Mar 1, 2010 at 4:06 PM

Just to confirm what I was saying earlier the enterprise libary dlls that I am referencing are located in this folder, "C:\Program Files\Microsoft Enterprise Library 4.1 - October 2008\Bin". I went through each of my projects and removed references to the dlls and then added them back to, but making sure I was pointing to the correct bin folder. However, I am still not getting anywhere. I am able to run my service and even debug to see that the Validation.Validate(some object) gets called, but for some reason I get the same result everytime, which leads me to believe the external config is never being read or used for reasons unknown to me.

Mar 1, 2010 at 7:27 PM

Does anyone have any ideas or recommendations?

I recently tried this method<font size="2">

 

</font>

Validator<TestObject> validator = ValidationFactory.CreateValidator<TestObject>(new FileConfigurationSource("C:\\Program Files\\TestApp\\Bin\\Validation.config"));

<font size="2" color="#2b91af"><font size="2" color="#2b91af">

ValidationResults

</font></font><font size="2" color="#2b91af">

 

</font>

testResults = validator.Validate(testObject);

I ended up with an exception being thrown. That says

System.Configuration.ConfigurationErrorsException was unhandled by user code

  Message="An error occurred creating the configuration section handler for validation: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

  Source="System.Configuration"

       FileName="Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null"

       FusionLog="=== Pre-bind state information ===\r\nLOG: User = NT AUTHORITY\\SYSTEM\r\nLOG: DisplayName = Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null\n (Fully-specified)\r\nLOG: Appbase = file:///C:/Program Files/TestApp/Bin/\r\nLOG: Initial PrivatePath = NULL\r\nCalling assembly : System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.\r\n===\r\nLOG: This bind starts in default load context.\r\nLOG: Using application configuration file: C:\\Program Files\\TestApp\\Bin\\MyTestApp.Validation.exe.Config\r\nLOG: Using machine configuration file from c:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\config\\machine.config.\r\nLOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).\r\nLOG: Attempting download of new URL file:///C:/Program Files/TestApp/Bin/Microsoft.Practices.EnterpriseLibrary.Validation.DLL.\r\nWRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN\r\nERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.\r\n"

Perhaps this might shed some new light on what I am doing wrong so that I can correct this issue I am facing, Thanks.

Mar 2, 2010 at 1:58 AM

Hi,,

This one is more familiar. I was just wondering, how did you create the Validation.config, do you use the ent lib config tool from C:\Program Files\Microsoft Enterprise Library 4.1 - October 2008\Bin? or the one from the Ent lib source. Because if you use the one from the program files, it would have a public key token. Unlike the one from the error message where the public key token is null.

Try changing the public key token to the proper one.

Here is a FAQ item for the said error:

http://entlib.codeplex.com/wikipage?title=Why%20am%20I%20getting%20the%20messages%2c%20%22Could%20not%20load%20file%20or%20assembly%22&referringTitle=EntLib%20FAQ

Valiant Dudan
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Mar 2, 2010 at 4:11 PM
Edited Mar 4, 2010 at 8:44 PM

Hey  Valiant,

I've got an update. I believe I have properly gac the Common and Validation dlls, and copied them to "C:\Program Files\TestApp\Bin" location, along with the ObjectBuilder2 dll; not gac by the way. The issue I am facing now is that the Validation.Validate(...) method always returns validationResults back with no errors no matter what. HOWEVER, I tried using the following functionality

 

Validator<TestApp> validator =ValidationFactory.CreateValidator<TestApp>(new FileConfigurationSource("C:\\Program Files\\TestApp\\Bin\\Validation.config"));

ValidationResults testResults = validator.Validate(testApp);

and for some reason it works! This is VERY puzzling to me. Any thoughts?

Mar 3, 2010 at 1:47 AM

As I mentioned in the other thread you posted, you don't need to GAC any entlib assemblies.  Please check that thread http://entlib.codeplex.com/Thread/View.aspx?ThreadId=203436.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com