how to Create Custom exception handler using enterprise Library 4.1

Topics: Enterprise Library Core, Exception Handling Application Block
Feb 3, 2009 at 9:32 AM

I used the below code and got error in the first line :[[ConfigurationElementType(typeof(CustomHandlerData))]]
Unable to find the Micrsoft.practises.EnterpriseLibrary.common.configuration.dll in Enterprise Library 4.1
Please help

[ConfigurationElementType(typeof(CustomHandlerData))]
public class AppMessageExceptionHandler : IExceptionHandler
{
  public AppMessageExceptionHandler(NameValueCollection ignore)
  {
  }

  public Exception HandleException(Exception exception, Guid handlingInstanceId)
  {
    DialogResult result = this.ShowThreadExceptionDialog(exception);

    return exception;
  }

  // Creates the error message and displays it.
  private DialogResult ShowThreadExceptionDialog(Exception ex)
  {
    string errorMsg = "The following exception was caught by the QuickStart Global Exception Handler:"
                    + Environment.NewLine + Environment.NewLine;

    StringBuilder sb = new StringBuilder();
    StringWriter writer = new StringWriter(sb);

    AppTextExceptionFormatter formatter = new AppTextExceptionFormatter(writer, ex, handlingInstanceID);

    // Format the exception.
    formatter.Format();

    errorMsg +=  sb.ToString();

    return MessageBox.Show(errorMsg, "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
  }
}

Feb 3, 2009 at 11:54 AM
Hi,

Make sure to add assembly reference to the Micrsoft.practises.EnterpriseLibrary.Common.dll and make sure to add the using statements to your class.

Like this:

using

Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

 

using

Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration;

 

using

Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;


Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Feb 3, 2009 at 12:00 PM
Edited Feb 3, 2009 at 12:14 PM
Thanks for the reply. I already included all references mentioned above.
Still i get the error in the second line of the above code.
Error that i got:
The type 'Microsoft.Practices.EnterpriseLibrary.Common.Configuration.NameTypeConfigurationElement' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
Feb 3, 2009 at 1:35 PM
Edited Feb 3, 2009 at 1:38 PM
Hi,

Did you just copy your custom exception handler from the quick start? If that is the case, if you copied it and add it into another project, you must add a assembly reference to the (Micrsoft.practises.EnterpriseLibrary.Common.dll and Micrsoft.practises.EnterpriseLibrary.ExceptionHandling.dll) Signed assemblies of the Ent Lib. Usually found in the installation directory  . Ex: C:\Program Files\Microsoft Enterprise Library 4.1 - October 2008\Bin....

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Feb 3, 2009 at 2:03 PM
i added mentioned assembly refrences from the installtion directory, but it still i am getting the same error.
Feb 4, 2009 at 3:07 AM

Can you check the bin/Debug folder of your project and see if the assembly is there? Is it a runtime or compile error?  It should work, try to clean first your solution, then do a rebuild.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
 
Feb 4, 2009 at 4:14 AM
After checking the reference in bin folder, I am still getting the following error

"The type 'Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ICustomProviderData' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. "

please suggest.

Feb 4, 2009 at 4:31 AM
Is it a runtime or compile error? Are you sure you're referencing the correct version? Do you have other versions of entlib installed before? 


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Feb 4, 2009 at 5:09 AM
Edited Feb 4, 2009 at 5:11 AM
Is a run time error and I don't have any other version of entlib installed.
I installed only entlib 4.1
Feb 4, 2009 at 5:13 AM
It'll be better if you could send me your solution,


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com