WCF Validation Behavior Issue

Topics: Validation Application Block
May 13, 2010 at 6:02 AM
Edited May 13, 2010 at 6:03 AM

When adding the validation behavior to my service contract, I get an error when launching my web service.  The error is below along with my code snippet.  If I remove the ValidationBehavior, the error goes away.   I did not think I needed any other setup for the validation block to work with WCF other than the attribute.  My data contracts are tagged with validation block attributes.

[ServiceContract(Namespace = Namespaces.Services, ConfigurationName = "IEmployeeDataService")]
    [ValidationBehavior]
    public interface IEmployeeDataService
    {
       ...Rest of interface

The type ValidatorFactory cannot be constructed. You must configure the container to supply this value.  I am using unity in my configuration file and within the service code to create dependent objects although I would not expect that to interfere with anything.  I am using default endpoints and File-Less Activation, but I would not expect that to be an issue either.

[InvalidOperationException: The type ValidatorFactory cannot be constructed. You must configure the container to supply this value.]
   Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor) +273
   Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) +356
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +262
   Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey) +187
   Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +221
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +262
   Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +377

[ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Validation.ValidatorFactory", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type ValidatorFactory cannot be constructed. You must configure the container to supply this value.
-----------------------------------------------
At the time of the exception, the container was:

  Resolving Microsoft.Practices.EnterpriseLibrary.Validation.ValidatorFactory,(none)
]

 

 

May 13, 2010 at 6:31 AM

I tried to add the ValidationBehavior attribute but didn't get the exception you're getting.  Is it possible for you to send me a repro project for this?

 

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

May 13, 2010 at 5:12 PM
Edited May 13, 2010 at 5:32 PM

Sure.  Should I send to the entlib.support email?  This also occurs with a simple Wcf service using the default template in Visual Studio 2010.  I am running Windows 7 x64, Visual Studio 2010 and .Net 4.0 application pools.

May 14, 2010 at 12:55 AM
Edited May 14, 2010 at 1:27 AM

I haven't checked the solution file you sent to me as I don't have visual studio 2010 on my machine right now.  However, I would like to ask if your referencing the Validation assembly from GAC (Copy Local = false).  If yes, there's an issue regarding this. Please check this work item in the issue tracker for the workaround - http://entlib.codeplex.com/WorkItem/View.aspx?WorkItemId=26903.

 

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

May 14, 2010 at 2:20 AM
Edited May 14, 2010 at 2:22 AM
The issue was resolved by removing the assemblies from the GAC and copying them local.  Very disapponting that the assemblies cannot be Gac'd.  
May 14, 2010 at 2:27 AM

You can still reference it from GAC, but you need to add the typeRegistrationProvidersConfiguration section in your config as suggested in the work item.

 

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

May 17, 2010 at 2:34 AM

  I did not read down to the workaround before my previous post.  Thanks for the reply and the workaround is fine for a solution.