Getting InvalidOperatorException issue while creating ValidatorFactory object.

Topics: Enterprise Library Core, General discussion, Validation Application Block
Dec 9, 2011 at 5:32 AM

Hi,

Brief Description: I am getting "InvalidOperationException - The type ValidatorFactory cannot be constructed. You must configure the container to supply this value." in Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive() while trying to construct ValidationFactory object.

Detailed Description: I had downloaded Enterprise Application Blocks(EAB) 5.0 and debugged the Validation sample code which worked fine. I wanted to debug the flow in depth to see how the ValidatorFactory object is created using object builder and other details for which I need to debug  Unity 2.0. Hence I downloaded Unity source code  from the CodePlex site (as unity source code was not available with EAB 5.0), compiled it in debug mode and recomplied Validation Block and Common with the new Unity debug dll. Now, I am able to debug into Unity from Validation block, but, I am facing a new issue after I recompile the unity code. I have attached the exception details and stack trace below:

FYI: I had tried compiling with various changeset of Unity like unity-50871, unity-63122, unity-67949.

Inner Exception : {"Resolution of the dependency failed, type = \"Microsoft.Practices.EnterpriseLibrary.Validation.ValidatorFactory\", name = \"(none)\".\r\nException occurred while: while resolving.\r\nException is: InvalidOperationException - The type ValidatorFactory cannot be constructed. You must configure the container to supply this value.\r\n-----------------------------------------------\r\nAt the time of the exception, the container was:\r\n\r\n  Resolving Microsoft.Practices.EnterpriseLibrary.Validation.ValidatorFactory,(none)\r\n"}

StackTrace: "   at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor) in D:\\Projects\\TSAB\\Unity\\unity-63122\\Unity\\Unity\\Src\\ObjectBuilder\\Strategies\\BuildPlan\\DynamicMethod\\Creation\\DynamicMethodConstructorStrategy.cs:line 289\r\n   at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) in D:\\Projects\\TSAB\\Unity\\unity-63122\\Unity\\Unity\\Src\\ObjectBuilder\\Strategies\\BuildPlan\\DynamicMethod\\Creation\\DynamicMethodConstructorStrategy.cs:line 71\r\n   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in D:\\Projects\\TSAB\\Unity\\unity-63122\\Unity\\Unity\\Src\\ObjectBuilder\\Strategies\\StrategyChain.cs:line 110\r\n   at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey) in D:\\Projects\\TSAB\\Unity\\unity-63122\\Unity\\Unity\\Src\\ObjectBuilder\\Strategies\\BuildPlan\\DynamicMethod\\DynamicMethodBuildPlanCreatorPolicy.cs:line 48\r\n   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) in D:\\Projects\\TSAB\\Unity\\unity-63122\\Unity\\Unity\\Src\\ObjectBuilder\\Strategies\\BuildPlan\\BuildPlanStrategy.cs:line 37\r\n   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in D:\\Projects\\TSAB\\Unity\\unity-63122\\Unity\\Unity\\Src\\ObjectBuilder\\Strategies\\StrategyChain.cs:line 110\r\n   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in D:\\Projects\\TSAB\\Unity\\unity-63122\\Unity\\Unity\\Src\\UnityContainer.cs:line 512"

Please suggest me on whats going wrong here, I am unable to understand the issue here.

TIA,

Prem

Dec 9, 2011 at 6:26 AM

The exception almost always means that the block is not configured properly.

Are you configuring the Validation block using XML Configuration?  If so, verify that the fully qualified assembly names in configuration match what you have compiled.
E.g. what is the version number of your new build if it is different than in the configuration then update the config.  If you have not signed the build then verify that
PublicKeyToken=null in the configuration instead of with the token that is usually present.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Dec 9, 2011 at 11:44 AM

Thanks for your response. Please find my answers below for your questions.

>Are you configuring the Validation block using XML Configuration?  If so, verify that the fully qualified assembly names in configuration match what you have compiled.
Yes, I had configured the Validation block using XML configuration. The FQN is given correctly. FYI: This client is the same sample application downloaded from codeplex (EntLib Dev Guide RC - Code Samples) and the same configuration is working when the original Unity DLL is referenced.

In the configuration file, I did try by removing the Version and public key for the Validation Section. I also tried with Version and public key as null. Still I am facing the same issue. Could there be any other reason as to why I am facing this issue (or) is there any other way to troubleshoot the issue?

Please advice.

TIA,

Prem

Dec 9, 2011 at 11:01 PM

Can you capture the exception and all nested InnerExceptions?  

You can also run the Assembly Binding Log Viewer which should show you any assemblies binding failures.

 

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com