Wcf Exception Handling Block Error

Topics: Exception Handling Application Block
Nov 2, 2011 at 7:22 AM

Hi,

I implemented the code for Exception blocks with wcf. It was getting executed successfully. But, all of a sudden it started throwing error when I make a call to the policy that I have configured. It throws error on the following line

 gBoolRethrow = ExceptionPolicy.HandleException(Staging_Exception, "Policy")
            If gBoolRethrow Then
                Throw New FaultException(Of ValidationException)(objValidationException, New FaultReason("EndPoint Validation Error occurred.."))
            End If

The error says.. "Activation error occured while trying to get instance of type ExceptionPolicyImpl, key "Policy"

Upon checking the possible solution I found that it may be due to:

1. unable to connect to database OR 2. Giving wrong name in policy. But, I have taken care of all these points. Could you pls. tell how to resolve this?  Thnx in advance

The details of the error are,

Message: Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type ExceptionPolicyImpl, key "Policy" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl", name = "Policy".

Exception occurred while: Calling constructor Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler(Microsoft.Practices.EnterpriseLibrary.Common.Utility.IStringResolver exceptionMessageResolver, System.Type faultContractType, System.Collections.Specialized.NameValueCollection attributes).

Exception is: ArgumentNullException - Value cannot be null.

Parameter name: faultContractType

-----------------------------------------------

At the time of the exception, the container was:

   Resolving Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl,Policy

  Resolving parameter "policyEntries" of constructor Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl(System.String policyName, System.Collections.Generic.IEnumerable`1[[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] policyEntries)

    Resolving Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry,Policy.All Exceptions

    Resolving parameter "handlers" of constructor Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry(System.Type exceptionType, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.PostHandlingAction postHandlingAction, System.Collections.Generic.IEnumerable`1[[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.IExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] handlers, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Instrumentation.IExceptionHandlingInstrumentationProvider instrumentationProvider)

      Resolving Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler,Policy.All Exceptions.Fault Contract Exception Handler (mapped from Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.IExceptionHandler, Policy.All Exceptions.Fault Contract Exception Handler)

      Calling constructor Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler(Microsoft.Practices.EnterpriseLibrary.Common.Utility.IStringResolver exceptionMessageResolver, System.Type faultContractType, System.Collections.Specialized.NameValueCollection attributes)

 ---> System.ArgumentNullException: Value cannot be null.

Parameter name: faultContractType

   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler..ctor(IStringResolver exceptionMessageResolver, Type faultContractType, NameValueCollection attributes) in c:\EntLib\Entlib\Source\Blocks.Desktop\ExceptionHandling\Src\WCF\FaultContractExceptionHandler.cs:line 84

   at BuildUp_Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler(IBuilderContext )

   at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlan.cs:line 37

   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs:line 43

   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:line 110

   at Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\BuilderContext.cs:line 220

   at Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilderCustomization\NamedTypeDependencyResolverPolicy.cs:line 51

   at Microsoft.Practices.Unity.ResolvedArrayWithElementsResolverPolicy.DoResolve[T](IBuilderContext context, IDependencyResolverPolicy[] elementPolicies) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilderCustomization\ResolvedArrayWithElementsResolverPolicy.cs:line 73

   at Microsoft.Practices.Unity.ResolvedArrayWithElementsResolverPolicy.Resolve(IBuilderContext context) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilderCustomization\ResolvedArrayWithElementsResolverPolicy.cs:line 64

   at BuildUp_Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry(IBuilderContext )

   at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlan.cs:line 37

   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs:line 43

   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:line 110

   at Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\BuilderContext.cs:line 220

   at Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilderCustomization\NamedTypeDependencyResolverPolicy.cs:line 51

   at Microsoft.Practices.Unity.ResolvedArrayWithElementsResolverPolicy.DoResolve[T](IBuilderContext context, IDependencyResolverPolicy[] elementPolicies) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilderCustomization\ResolvedArrayWithElementsResolverPolicy.cs:line 73

   at Microsoft.Practices.Unity.ResolvedArrayWithElementsResolverPolicy.Resolve(IBuilderContext context) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilderCustomization\ResolvedArrayWithElementsResolverPolicy.cs:line 64

   at BuildUp_Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl(IBuilderContext )

   at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlan.cs:line 37

   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs:line 43

   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:line 110

   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 512

   --- End of inner exception stack trace ---

   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 516

   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 486

   at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 173

   at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key) in c:\EntLib\UnityTemp\Compile\Unity\Unity\Src\UnityServiceLocator.cs:line 64

   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 49

   --- End of inner exception stack trace ---

   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 53

   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService](String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 103

   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName) in c:\EntLib\Entlib\Source\Blocks.Desktop\ExceptionHandling\Src\ExceptionHandling\ExceptionPolicy.cs:line 131

   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName) in c:\EntLib\Entlib\Source\Blocks.Desktop\ExceptionHandling\Src\ExceptionHandling\ExceptionPolicy.cs:line 55

   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.ExceptionShieldingErrorHandler.ProvideFault(Exception error, MessageVersion version, Message& fault) in c:\EntLib\Entlib\Source\Blocks.Desktop\ExceptionHandling\Src\WCF\ExceptionShieldingErrorHandler.cs:line 98

 

Nov 2, 2011 at 10:32 AM

It looks like you are using exception shielding but have not provided a fault contract.

Can you post your configuration?

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

Nov 3, 2011 at 5:54 AM

The configuration goes as below..
<exceptionHandling>
    <exceptionPolicies>
      <add name="Policy">
        <exceptionTypes>
          <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="ThrowNewException">
            <exceptionHandlers>
              <add type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                exceptionMessageResourceType="" faultContractType="test.Service_Exception, People, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Fault Contract Exception Handler">
                <mappings>
                  <add source="{GuId}" name="Id" />
                  <add source="{Message}" name="MessageText" />
                </mappings>
              </add>
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>

Could you also tell me why do we always get faultContractType="test.Service_Exception, People, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" as the Warning ?

Thnx in advance..

Nov 3, 2011 at 8:12 AM

The Activation Error means that the container could not create the object.  This is usually a configuration error or the wrong key.

Can you email a sample project to reproduce the problem?

 

Thanks,

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

Nov 3, 2011 at 9:13 AM

Ok.. i will do that

Could you also tell me why do we always get faultContractType="test.Service_Exception, People, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" as the Warning ?

I want to know the reason behind it and can we remove taht? BECause in all internet post i saw this error.. If yes, how to remove that?

Nov 4, 2011 at 10:54 PM
Edited Nov 5, 2011 at 12:54 AM

The message is a warning by the configuration tool and can safely be ignored.  

The reason why the warning appears is that at runtime the configuration tool cannot locate the assembly in question (People.dll in your case).  

If you really want to remove the warning you can copy the assembly to the directory where the configuration tool executable is located (the default is C:\Program Files (x86)\Microsoft Enterprise Library 5.0\Bin or C:\Program Files\Microsoft Enterprise Library 5.0\Bin). Although the "cure" might be a bit worse than the "disease" in this instance. 

 

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

Nov 28, 2011 at 4:15 PM
amittongaonkar wrote:

Could you also tell me why do we always get faultContractType="test.Service_Exception, People, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" as the Warning ?

As a quick solution, I recommend you to put your dll into EntLib bin folder and use the EntLib configurator to make fualtContactType. I got similar issue and the problem was in a typo in namespace in the code.