ExceptionPolicy.HandleException issue

Topics: Exception Handling Application Block, Logging Application Block
Apr 15, 2009 at 4:56 PM
I have an ASP.NET MVC app that I wrote an error handling IHttpModule for.     I think my current policy is for all exceptions to throw as the original exception.    However, when I call ExceptionPolicy.HandleException, newException points to a bizarre enterprise library exception:

The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, ZFP Base Policy]) failed: The type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' cannot be resolved. Please verify the spelling is correct or that the full type name is provided. (Strategy type ConfiguredObjectStrategy, index 2)"}
    [Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException]: {"The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, ZFP Base Policy]) failed: The type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' cannot be resolved. Please verify the spelling is correct or that the full type name is provided. (Strategy type ConfiguredObjectStrategy, index 2)"}
    Data: {System.Collections.ListDictionaryInternal}
    HelpLink: null
    InnerException: {"The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, ZFP Base Policy]) failed: The type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' cannot be resolved. Please verify the spelling is correct or that the full type name is provided. (Strategy type ConfiguredObjectStrategy, index 2)"}
    Message: "The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, ZFP Base Policy]) failed: The type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' cannot be resolved. Please verify the spelling is correct or that the full type name is provided. (Strategy type ConfiguredObjectStrategy, index 2)"
    Source: "Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
    StackTrace: "   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName, ExceptionPolicyFactory factory)\r\n   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName, ExceptionPolicyFactory policyFactory)\r\n   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName, ExceptionPolicyFactory policyFactory, Exception& exceptionToThrow)"
    TargetSite: {Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl GetExceptionPolicy(System.Exception, System.String, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyFactory)}

Here is the code:

protected void Exception(object sender, EventArgs e)
        {
            HttpApplication app = sender as HttpApplication;

            Exception originalException = app.Server.GetLastError().GetBaseException();

            Debug.WriteLine(originalException.ToString());            
            
            Exception newException;

            bool rethrow = ExceptionPolicy.HandleException(originalException, Properties.Settings.Default.ExceptionPolicyName, out newException);
            if (rethrow)
            {
                if (newException != null)
                {
                    Debug.WriteLine(newException.ToString());

                    throw newException;
                }
                throw originalException;
            }
        }


Anyone else had this issue?

thanks
Apr 15, 2009 at 8:05 PM
Doh!

Apparently, when you use the Exception handling block to perform logging, you must also include a reference to:

C:\Program Files\Microsoft Enterprise Library 4.1 - October 2008\Bin\Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll