ConfigurationErrorsException with SqlExceptionWrapHandler

Topics: Development Team Discussion, User Discussion
Feb 13, 2008 at 10:39 PM
Edited Feb 15, 2008 at 9:20 PM

I'm getting the exception below when I try to wrap a SqlException using the SqlExceptionWrapHandler. It is complaining about an unrecognized element named "errorCodes". That element is definitely in the config file and it is put there by the Enterprise Library Configuration Editor. After looking at the Contrib source code, it appears that errorCodes is a valid element.

Does anyone know what's going on here?

Thanks,
Brian

Test method Bong.Mme.Dp.Crick.Services.Tests.ServiceTests.AddTwoProgramsWithSameNameTest threw exception System.Configuration.ConfigurationErrorsException, but exception System.ServiceModel.FaultException`1[Bong.Mme.Dp.Crick.Subsystems.DataAccessMgr.DuplicateKeyException, Bong.Mme.Dp.Crick.Subsystems.DataAccessMgr, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] was expected. Exception message: System.Configuration.ConfigurationErrorsException: Unrecognized element 'errorCodes'. (C:\DevP8A\P-8A Test Data Warehouse\Crick\Services\TestResults\ty814cA3947474 2008-02-13 1623_27\Out\CrickUnitTests.dll.config line 19)

at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
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, Boolean getLkg, Boolean checkPermission)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSourceImplementation.GetSection(String sectionName)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource.GetSection(String sectionName)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings.GetExceptionHandlingSettings(IConfigurationSource configurationSource)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingConfigurationView.GetExceptionPolicyData(String policyName)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUpTTypeToBuild(IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUpT(IReadWriteLocator locator, String id, IConfigurationSource configurationSource)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.LocatorNameTypeFactoryBase`1.Create(String name)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName, ExceptionPolicyFactory factory)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName)
at Bong.Mme.Dp.Crick.Subsystems.DataAccessMgr.PrograMmenager.AddProgram(String programName, String programDescription) in C:\DevP8A\P-8A Test Data Warehouse\Crick\Services\Bong.Mme.Dp.Crick\Source\Business Logic\Subsystems\Bong.Mme.Dp.Crick.Subsystems.DataAccess\PrograMmenager.cs:line 58
at Bong.Mme.Dp.Crick.ServiceImplementation.CrickService.AddProgram(AddProgramRequest request) in C:\DevP8A\P-8A Test Data Warehouse\Crick\Services\Bong.Mme.Dp.Crick\Source\Service Interface\Bong.Mme.Dp.Crick.ServiceImplementation\CustomCode\CrickService.Custom.cs:line 34
at Bong.Mme.Dp.Crick.Services.Tests.ServiceTests.AddTwoProgramsWithSameNameTest() in C:\DevP8A\P-8A Test Data Warehouse\Crick\Services\Bong.Mme.Dp.Crick\Tests\Unit Tests\CrickTests\CrickUnitTests\ServiceTests.cs:line 104

App.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<section name="validation" type="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationSettings, Microsoft.Practices.EnterpriseLibrary.Validation, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<section name="repositoryFactory" type="Microsoft.Practices.Repository.Configuration.RepositoryFactorySection, Microsoft.Practices.Repository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
<exceptionHandling>
<exceptionPolicies>
<add name="Data Access Policy">
<exceptionTypes>
<add type="System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="NotifyRethrow" name="SqlException">
<exceptionHandlers>
<add defaultExceptionMessage="" defaultWrapExceptionType="System.Exception"
errorCodeNotConfiguredBehavior="WrapWithDefaultException" type="EntLibContrib.ExceptionHandling.SqlExceptionWrapHandler, EntLibContrib.ExceptionHandling, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
name="SqlExceptionWrapHandler">
<errorCodes>
<add errorCode="2601" wrapExceptionTypeName="Bong.Mme.Dp.Crick.Subsystems.DataAccessMgr.DuplicateKeyException, Bong.Mme.Dp.Crick.Subsystems.DataAccessMgr, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
exceptionMessage="Name already exists." name="Duplicate Keys" />
</errorCodes>
</add>
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
<validation>
...

Feb 20, 2008 at 9:07 AM
I had the same issue. make sure the code that is using the exception policy handler is referencing also the EntLibContrib.Data.SqlEx.dll, EntLibContrib.ExceptionHandling.dll and EntLibContrib.ExceptionHandling.Design.dll

not really sure if the last one is required, I added it just in case... ;-)
Feb 20, 2008 at 7:53 PM


baruchl wrote:
I had the same issue. make sure the code that is using the exception policy handler is referencing also the EntLibContrib.Data.SqlEx.dll, EntLibContrib.ExceptionHandling.dll and EntLibContrib.ExceptionHandling.Design.dll

not really sure if the last one is required, I added it just in case... ;-)


Thank you! That did it! It's one of those things that makes sense after someone tells you. Also, your suspicion that the Design DLL was not needed is correct. It works fine without including a reference to it.

Thanks again,
Brian