Wednesday, May 23, 2007

Implementing IExceptionHandler

When using the Enterprise Library Exception Handling Block, there are (at least) two things that you have to do to get your custom handler to work that I missed when I looked at the docs. Specify CustomHandlerData as the ConfigurationElementType for the handler class:

[ConfigurationElementType(typeof(CustomHandlerData))]
public class WatchdogHandler : IExceptionHandler {
...

Provide a constructor that takes a NameValueCollection:

public WatchdogHandler(NameValueCollection attributes) { }

Final note.

I have had weird problems with the Enterprise Library Configuration tool. When I first created the handler class it would not load the assembly in the tool. It said that no class that implemented IExceptionHandler could be found. When I fixed the problems with my class it still would not load. Frustrated, I created another handler class from scratch (no other classes in the assembly, no other bits of code lurking around to cause problems) and that one loaded. Then, magically, the other class loaded as well!? Perhaps it was after all the closing and re-opening of the tool that it started to work, but I am not convinced.

1 comment:

  1. Thank you, thank you, thankyou! I've been looking for this all morning. Knew the exception I was getting ment I needed an additional constuctor, but couldn't find details on what it should be.

    Sorted now, thanks

    ReplyDelete