Exception handler issue when upgrading from 4.1 to 6

Topics: Exception Handling Application Block
Apr 2, 2014 at 2:19 PM
Hi, I am getting this error message after upgrading from Enterprise Library 4.1 to 6.

"Must set an ExceptionManager in the ExceptionPolicy class using the SetExceptionManager method"

I have the web.config section configured as below:

  <add name="Business Logic Layer">
    <exceptionTypes >
      <add name="Exception" type="System.Exception, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow">
          <add logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" priority="0" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging" name="Logging Handler"/>

And am catching errors using:
        catch (Exception ex)
            bool rethrow = ExceptionPolicy.HandleException(ex, "Business Logic Layer");
            if (rethrow) { throw; }
We use the "ExceptionPolicy.HandleException(...)" line in hundreds of files so I don't want to have to change this line.

Where in code would I set the ExceptionManager using the SetExceptionManager method?

Apr 3, 2014 at 12:07 AM
We use the "ExceptionPolicy.HandleException(...)" line in hundreds of files so I don't want to have to change this line.
The good news is you don't need to. You just need to initialize the block once at application startup (this could be Application_Start in global.asax since your application is a web application):
            IConfigurationSource source = ConfigurationSourceFactory.Create();

            var logwriterFactory = new LogWriterFactory(source);
            var logWriter = logwriterFactory.Create();

            var exceptionPolicyFactory = new ExceptionPolicyFactory(source);
            var exceptionManager = exceptionPolicyFactory.CreateManager();

I also initialized the logging block since it looks like you are using logging as well.

Randy Levy
Enterprise Library support engineer
Support How-to
Marked as answer by andyedwards12 on 4/3/2014 at 12:42 AM
Apr 3, 2014 at 8:43 AM
That worked perfectly! Thanks for you help.