0

我正在尝试创建用于 EHAB 的自定义异常处理程序。我所能找到的只是 IExceptionHandler 接口,它只需要 HandleException 方法。但是,显然还有其他要求,因为我得到了这个例外:

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)."}

如果有一个“预期的构造函数”,我如何找到关于它的文档?我应该从基类以及 IExceptionHandler 接口继承吗?(“临时...”课程只是我用来解决问题的沙箱,不会是最后的课程...)

更多信息:我的“沙盒”异常处理程序类如下:

[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;
    }
}

我只是通过在 EntLib 配置实用程序中打开一个对话框来选择自定义处理程序类(在对话框的标题栏中)看到它才弄清楚对“[ConfigurationElementType(typeof(CustomHandlerData))]”属性的要求,但我不知道这意味着什么其他要求。

4

1 回答 1

1

有关示例,请参阅创建自定义提供程序。还有Enterprise Library 5.0 - Extensibility Labs,它介绍了各种异常处理场景。

以上适用于 Enterprise Library 5,但大多数细节仍然适用于 Enterprise Library 6。一个例外是GetRegistrations覆盖将被BuildExceptionHandler覆盖替换。

NameValueCollection构造函数而言,它与基本设计时集成一起使用。所有 XML 属性都作为名称值对传递给构造函数,并且类可以适当地提取和使用这些值。

Enterprise Library 6 现在拥有自己的动手实验室

于 2013-09-02T05:20:16.000 回答