Configuration error could not load file or assembly

Topics: Exception Handling Application Block
Nov 30, 2011 at 10:55 AM

Hi All,

I've implemented a sample code in wcf with Enterprise library but i'm getting following error

 

Server Error in '/' Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: An error occurred creating the configuration section handler for exceptionHandling: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error:

Line 3:    
Line 4:    <configSections>
Line 5:      <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
Line 6:    </configSections>
Line 7:  


Source File: C:\Documents and Settings\296992\my documents\visual studio 2010\Projects\TestService\Client\web.config    Line: 5

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

 


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

 My config file is

  

  

 

please let me know what's the problem.

Thank You

Pradi18

<!-- [FileLoadException]: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) at System.Configuration.TypeUtil.GetTypeWithReflectionPermission(IInternalConfigHost host, String typeString, Boolean throwOnError) at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.Init(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord) at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.InitWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord) at System.Configuration.RuntimeConfigurationRecord.CreateSectionFactory(FactoryRecord factoryRecord) at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere) [ConfigurationErrorsException]: An error occurred creating the configuration section handler for exceptionHandling: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) (C:\Documents and Settings\296992\my documents\visual studio 2010\Projects\TestService\Client\web.config line 5) at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Web.HttpContext.GetSection(String sectionName) at System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName) at System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource.DoGetSection(String sectionName) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\SystemConfigurationSource.cs:line 120 at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileBasedConfigurationSource.GetSection(String sectionName) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\FileBasedConfigurationSource.cs:line 103 at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ConfigSectionLocator.GetRegistrationsInternal(IConfigurationSource configurationSource, Func`3 registrationsAccessor) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\ConfigSectionLocator.cs:line 80 at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ConfigSectionLocator.GetRegistrations(IConfigurationSource configurationSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\ConfigSectionLocator.cs:line 60 at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.CompositeTypeRegistrationsProviderLocator.<GetRegistrations>b__0(ITypeRegistrationsProvider l, IConfigurationSource cs) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\TypeRegistrationsProvider.cs:line 128 at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.CompositeTypeRegistrationsProviderLocator.<>c__DisplayClass5.<GetRegistrationsInternal>b__4(ITypeRegistrationsProvider l) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\TypeRegistrationsProvider.cs:line 147 at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext() at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator.RegisterAllCore(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\Unity\UnityContainerConfigurator.cs:line 61 at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ChangeTrackingContainerConfigurator.RegisterAll(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\ChangeTrackingContainerConfigurator.cs:line 66 at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.ConfigureContainer(IContainerConfigurator configurator, IConfigurationSource configSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 61 at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer(IConfigurationSource configurationSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 119 at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet() in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 90 at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.get_Current() in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 35 at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName) in e:\Builds\EntLib\Latest\Source\Blocks\ExceptionHandling\Src\ExceptionHandling\ExceptionPolicy.cs:line 120 [ExceptionHandlingException]: An error occurred creating the configuration section handler for exceptionHandling: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) (C:\Documents and Settings\296992\my documents\visual studio 2010\Projects\TestService\Client\web.config line 5) at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName) in e:\Builds\EntLib\Latest\Source\Blocks\ExceptionHandling\Src\ExceptionHandling\ExceptionPolicy.cs:line 144 at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName) in e:\Builds\EntLib\Latest\Source\Blocks\ExceptionHandling\Src\ExceptionHandling\ExceptionPolicy.cs:line 55 at Client.Business_Layer.MathBL.GetValue(Int32 a, Int32 b, String r) in C:\Documents and Settings\296992\my documents\visual studio 2010\Projects\TestService\Client\Business Layer\MathBL.cs:line 58 at Client._Default.btn_Click(Object sender, EventArgs e) in C:\Documents and Settings\296992\my documents\visual studio 2010\Projects\TestService\Client\Default.aspx.cs:line 28 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.default_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\18629e29\f123061c\App_Web_zj5ouc5g.1.cs:line 0 at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) -->

Dec 1, 2011 at 2:00 AM

By the error message, it sounds like the assembly you have referenced (strongly named version 5.0.414.0) can't be found.  Usually this would be because
the deployed assembly is the wrong version (perhaps 5.0.505.0) or is an unsigned version (from the source bin folder?).

Can you verify that all of the assemblies are present in the deployment folder and that they are version 5.0.414.0 and are also signed with key 31bf3856ad364e35?

If the problem persists, you can download Assembly Binding Log Viewer which should tell you exactly what assembly is failing and what paths were searched.

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

Dec 1, 2011 at 8:52 AM

Hi randy,

Now i've added assembly with version 5.0.414.0 but then i'm getting different excetion

ActivatinException:

Activation error occured while trying to get instance of type ExceptionPolicyImpl, key \"WCF Exception Shielding\""

code:

try
 { 
ServiceReference1.MathServiceClient client = new ServiceReference1.MathServiceClient();
 re = client.Divison(a, b); 
} 
catch(FaultException ex)
 { 
bool reth = ExceptionPolicy.HandleException(ex, "WCF Exception Shielding"); //I'm getting above exception at this line.
if (reth) 
{ 
throw ex; 
}

 Thank You,

Pradi18

Dec 1, 2011 at 9:00 AM
My config file :
<?xml version="1.0"?>
<configuration>


  <configSections>
    <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>
  <exceptionHandling>
    <exceptionPolicies>
      <add name="WCF Exception Shielding">
        <exceptionTypes>
          <add name="DivideByZeroException" type="System.DivideByZeroException, 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.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                faultContractType="TestService.BasicMathFault, TestService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Fault Contract Exception Handler">
                <mappings>
                  <add source="Source" name="source" />
                  <add source="Message" name="ExceptionMessage" />
                  <add source="Exception" name="InnerException" />
                  <add source="Trace" name="StackTrace" />
                </mappings>
              </add>
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding  name="BasicHttpBinding" />
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="TestService.IMathService">
        
       <endpoint address="http://localhost:2324/Service1.svc"
                  binding="wsHttpBinding"
                  contract="TestService.IMathService">
          
        </endpoint>
                               
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <dataContractSerializer maxItemsInObjectGraph="6553600"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  
</configuration>

Dec 1, 2011 at 10:52 AM

What Enterprise Library assemblies do you have a reference to?

 

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

Dec 1, 2011 at 10:58 AM

Microsoft.Practices.EnterpriseLibrary.Common

Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll

Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF

Microsoft.Practices.Unity

 

Dec 1, 2011 at 10:57 PM

Thanks for the information.  Can you capture the full stack trace?  Usually an InnerException will contain a more detailed message that points to the root cause.

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

Dec 2, 2011 at 3:38 AM

Hi Randy,

here is the exception detail..

Microsoft.Practices.ServiceLocation.ActivationException was unhandled by user code

Message=Activation error occured while trying to get instance of type ExceptionPolicyImpl, key "WCF Exception Shielding"

Source=Microsoft.Practices.ServiceLocation

StackTrace:

       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 e:\Builds\EntLib\Latest\Source\Blocks\ExceptionHandling\Src\ExceptionHandling\ExceptionPolicy.cs:line 131

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

       at Client.Business_Layer.MathBL.GetValue(Int32 a, Int32 b, String r) in C:\Documents and Settings\296992\My Documents\Visual Studio 2010\Projects\TestService\Client\Business Layer\MathBL.cs:line 57

       at Client._Default.btn_Click(Object sender, EventArgs e) in C:\Documents and Settings\296992\My Documents\Visual Studio 2010\Projects\TestService\Client\Default.aspx.cs:line 28

       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)

       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)

       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)

       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)

       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)

       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

InnerException:

Microsoft.Practices.Unity.ResolutionFailedException

       Message=Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl", name = "WCF Exception Shielding".

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,WCF Exception Shielding

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.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] policyEntries)

   Resolving Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry,WCF Exception Shielding.DivideByZeroException

   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.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] handlers, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Instrumentation.IExceptionHandlingInstrumentationProvider instrumentationProvider)

     Resolving Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler,WCF Exception Shielding.DivideByZeroException.Fault Contract Exception Handler (mapped from Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.IExceptionHandler, WCF Exception Shielding.DivideByZeroException.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)

 

       Source=Microsoft.Practices.Unity

       NameRequested=WCF Exception Shielding

       TypeRequested=ExceptionPolicyImpl

       StackTrace:

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

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

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

           at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key) in e:\Builds\Unity\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

       InnerException: System.ArgumentNullException

           Message=Value cannot be null.

Parameter name: faultContractType

           Source=Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF

           ParamName=faultContractType

           StackTrace:

                 at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler..ctor(IStringResolver exceptionMessageResolver, Type faultContractType, NameValueCollection attributes) in e:\Builds\EntLib\Latest\Source\Blocks\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 e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlan.cs:line 37

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

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

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

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

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

                 at Microsoft.Practices.Unity.ResolvedArrayWithElementsResolverPolicy.Resolve(IBuilderContext context) in e:\Builds\Unity\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 e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlan.cs:line 37

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

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

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

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

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

                at Microsoft.Practices.Unity.ResolvedArrayWithElementsResolverPolicy.Resolve(IBuilderContext context) in e:\Builds\Unity\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 e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlan.cs:line 37

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

                 at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\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 e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 511

 Thank You

Pradeep

Dec 2, 2011 at 4:32 AM
Edited Dec 2, 2011 at 4:36 AM

The issue looks to be that your FaultContractType

TestService.BasicMathFault, TestService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

cannot be resolved at runtime.  Since the type cannot be resolved the Type variable passed into the FaultContractExceptionHandler
constructor is null and Enterprise Library throws an ArgumentNullException("faultContractType"). 

The solution is to ensure that your assembly is deployed to a location where it can be resolved by the WCF service at runtime
and that the configuration information (class name, assembly, version, etc.) match the deployed assembly.

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

Dec 2, 2011 at 5:14 AM

yeah i had doubt while selecting that FaultContracType as TestService.BasicMathFault, TestService,

Because i'm new this Enterprise Library thing.

Can u please tell me what should be the FaultContractType?

In my app it is the Class i've created BasicMathFault.

 My IService1.cs:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF;
namespace TestService
{
    [ServiceContract]
    public interface IMathService
    {
        [OperationContract]
        [FaultContract(typeof(BasicMathFault))]
        int mulitiplication(int x, int y);


        [OperationContract]
        [FaultContract(typeof(BasicMathFault))]
        int Divison (int x, int y);
    }

    [DataContract]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class BasicMathFault
    {

        public BasicMathFault()
        {
            this.ExceptionMessage = "Service encountered a problem";

        }

        public BasicMathFault(string message)
        {
            this.ExceptionMessage = message;

        }
        [DataMember]
        public string source;

        public string Source
        {

            get { return source; }

            set { source = value; }

        }

        [DataMember]
        public string ExceptionMessage;

        public string exceptionMessage
        {

            get { return ExceptionMessage; }

            set { ExceptionMessage = value; }


        }

        [DataMember]
        public string InnerException;

        public string innerException
        {

            get { return InnerException; }

            set { InnerException = value; }

        
        
        }

        [DataMember]
        public string StackTrace;

        public string stacktrace
        {

            get { return StackTrace; }

            set { StackTrace = value; }

        
        }

    
    }

}
My Service1.svc.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF;

namespace TestService
{
    [ExceptionShielding("WCF Exception Shielding")]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class Service1 : IMathService
    {
        public int mulitiplication(int x, int y)
        {
            int result = 0;
            try
            {
                result = (x * y);
            }
            catch 
            {
                BasicMathFault ex = new BasicMathFault();
                ex.source = "Math.Multiplication Method";
                ex.ExceptionMessage = "bCouldn't Perform Multiplication";
                ex.InnerException = "Inner Exception From Math Service";
                ex.StackTrace = "";

                throw new FaultException<BasicMathFault>(ex, new FaultReason(
                    "This is an error condition in math.multiplication method"));
            }

        return result;
            }

        public int Divison (int x, int y)
        {
            int result = 0;
           
            try 
        	{	        
		        result = (x/y);
	        }
	        catch
	            {
                 BasicMathFault ex = new BasicMathFault();
                 ex.source = "Math.Divsion method";
                 ex.ExceptionMessage = "Couldn't Perform divison";
                 ex.InnerException = "Inner Exception From Math Service";
                 ex.StackTrace = "";

                    throw new FaultException<BasicMathFault>(ex, new FaultReason("This  is an error condtion in math.Divison Method"),
                       new FaultCode("Divison.method.error"));
		            
	            }
            return result;

        }


        }
    }


Dec 2, 2011 at 6:03 AM

I was actually looking at an older post and it looks like you are manually applying the exception shielding policy in the client
(which is where your error was occuring).  Exception shielding should happen at the service boundary before returning to the client.  
That's probably why you can't resolve the MathFault at runtime -- it's a client side proxy object and not the MathFault that you are referencing in the configuration. 

Also, in your service you don't need to manually construct the FaultException as per your last post -- that is what the exception shielding is supposed to do for you.
It will map a regular .NET exception to a FaultException<T> as per the configuration.

I recommend reading WCF Exception Handling with Exception Handling Application Block Integration.

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

Dec 2, 2011 at 6:39 AM

Whatever you just replied, i didn't get it completely. you're saying i'm manually constructing the FaultException, so can you just show me from whic part of the code i've constructed FaultException manually

and i've tried this application by reading the above Blog only.

Thank You

Pradeep

Dec 2, 2011 at 10:46 AM

Here is where you create the FaultExceptions:

public int Divison (int x, int y)
        {
            int result = 0;
           
            try 
        	{	        
		        result = (x/y);
	        }
	        catch
	            {
                 BasicMathFault ex = new BasicMathFault();
                 ex.source = "Math.Divsion method";
                 ex.ExceptionMessage = "Couldn't Perform divison";
                 ex.InnerException = "Inner Exception From Math Service";
                 ex.StackTrace = "";

                    throw new FaultException<BasicMathFault>(ex, new FaultReason("This  is an error condtion in math.Divison Method"),
                       new FaultCode("Divison.method.error"));
		            
	            }
            return result;

        }

By annotating with the ExceptionShielding Attribute Enterprise Library should do this for you.

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

Dec 2, 2011 at 11:12 AM

Oh okay.

Previously i  created app for just handling Exception in WCF service. So wen had to use Enterterprise library i used this app only.

And also i didnt know clearly what it(Enterprise Library) does. So you're saying Enterterprise library will do all this. then what catch block should contain?

if u know then please let me know .

Thank You

Pradeep

Dec 2, 2011 at 11:31 PM
Edited Dec 2, 2011 at 11:37 PM

Pradeep, a good resource you could read to get a better understanding of Enterprise Library is Enterprise Library Developer's Guide.  If you are interested in Exception
Handing then look at Chapter 3 - Error Management Made Exceptionally Easy.

You can also download and work through the Hands-On Labs for Microsoft Enterprise Library 5.0.

On the client you can catch a FaultException and handle it using the Exception Handling block but you wouldn't use the exception shielding
policy -- you would create another policy. 

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

Dec 5, 2011 at 3:26 AM

Thanks a lot Randy..

Pradeep