Question

I am trying to create custom Exception handlers for use with the EHAB. All I have been able to find for how-to is the IExceptionHandler interface, which only requires the HandleException method. But, there are obviously other requirements, because I get this exception:

System.InvalidOperationException

   {"The type 'Paychex.IP.Common.TempClassLibrary.TempExceptionHandler, TempClassLibrary,
    Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' for custom exception handler
    with name 'TempExceptionHandler' does not have the expected constructor
    (C:\\Projects\\IP\\Common\\TempTestingConsole\\bin\\Debug\\TempTestingConsole.vshost.exe.Config 
    line 28)."}

If there is an "expected constructor," how to I find documentation on what that looks like? Am I supposed to inherit from a base class as well as the IExceptionHandler interface? (The 'temp...' classes are just my sandbox for figuring things out, would not be the final classes...)

MORE INFORMATION: My "sandbox" exception handler class is as follows:

[ConfigurationElementType(typeof(CustomHandlerData))]
public class TempExceptionHandler : IExceptionHandler
{
    public Exception HandleException(Exception exception, Guid handlingInstanceId)
    {
        string oldMsg = exception.Message;
        string newMsg = "Added by TempExceptionHandler: " + oldMsg;
        ApplicationException newException = new ApplicationException(newMsg);
        return newException;
    }
}

I only figured out the requirement for the "[ConfigurationElementType(typeof(CustomHandlerData))]" attribute by seeing it in the EntLib config utility when it opened a dialog to select the custom handler class (was in the title bar of the dialog), but I have no idea what other requirements that implies.

Was it helpful?

Solution

See Creating a Custom Provider for an example. There is also the Enterprise Library 5.0 - Extensibility Labs which walks through various exception handling scenarios.

The above are for Enterprise Library 5 but most of the details still apply for Enterprise Library 6. One exception is that the GetRegistrations override would be replaced with the BuildExceptionHandler override.

In terms of the NameValueCollection constructor, that is used with basic design time integration. All XML attributes are passed to the constructor as name value pairs and the class can extract and use those values as appropriate.

Enterprise Library 6 now has it's own Hands-On Labs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top