I started playing with Microsoft Enterprise Library 6.0 using .Net 4.5 and VS 2012.
I am trying to use the exception handling block and logging block to first log an exception and then replace the exception with another exception.
This is the configuration section:
<exceptionPolicies>
<add name="ReplaceWithFriendlyMessage">
<exceptionTypes>
<add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="ThrowNewException">
<exceptionHandlers>
<add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging,
Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
logCategory="General" eventId="100" severity="Error"
title="Enterprise Library Exception Handling"
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter,
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
priority="0" />
<add name="Wrap Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler,
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
exceptionMessage="Unexpected Error Occurred" wrapExceptionType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException,
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
This is how the exception handling factory is used at initialization:
Dim config As IConfigurationSource = ConfigurationSourceFactory.Create()
Dim factory As ExceptionPolicyFactory = New ExceptionPolicyFactory(config)
exManager = factory.CreateManager
exManager is of the type ExceptionManager and defined as an instance variable of the form.
I noticed that the factory.CreateManager code returns a null object with the configuration defined above. So my code throws a null reference exception later when I call exManager.Process or exManager.HandleException.
If I comment out the logging exception handler section, the exception manager gets loaded and handles the exception using the wrap exception handler. So if I comment out this text, the code works fine.
<!--<add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
logCategory="General" eventId="100" severity="Error"
title="Enterprise Library Exception Handling"
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter,
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
priority="0" />-->
I am inclined to say something is wrong in the configuration of Logging Exception Handler. The configuration section was added using the Enterprise Library 6.0 configuration tool. I am not sure why Exception Policy Factory does not throw an exception if the configuration is incorrect. Also, I compared my configuration with several working samples on the internet and they are identical to my settings with the exception of an older version of Enterprise Library reference.
I'll retry this in Ent Library 5 and see if I can find out something. In the meantime, I'll really appreciate any help with this issue. Thanks in advance.