使用MS异常处理块获取奇怪的异常

sab*_*669 3 c# enterprise-library exception-handling .net-3.5 winforms

我已经创建了一个非常基本的Logging块和异常处理块.在我的代码中,我去测试异常处理(我知道Logging块工作),具体如下:

    public void RunScriptClean()
    {
        try
        {
            throw new FileNotFoundException();
        }
        catch (FileNotFoundException ex)
        {
            var b = ExceptionPolicy.HandleException(ex, "Logging Policy");

            if (b)
                throw;
        }
    }
Run Code Online (Sandbox Code Playgroud)

但是,在catch块的第一行,我得到了这个冗长的异常,我的应用程序崩溃了:

Exception occured: The current build operating (build key Build Key [Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, Logging Policy]) failed: The type '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.Common/ExceptionHandling/Logging和Ms.Practices.ObjectBuilder2的引用.这一课using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling包括在顶部.

添加了查看我的AppConfig文件的配置工具的屏幕截图: 在此输入图像描述

我确定我遗漏了一些基本的东西,但很难找到EAB 4.1的教程 - CodeProject对于原始版本有很多东西,但是我不能做很多...

编辑我尝试创建一个新的Formatter并命名它,TextExceptionFormatter但没有改变任何东西.不确定FormatterType我的Logging Handler上的属性是如何绑定到该节点的.

来自App.config的实际XML块:

  <exceptionHandling>
    <exceptionPolicies>
      <add name="Logging Policy">
        <exceptionTypes>
          <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="NotifyRethrow" name="Exception">
            <exceptionHandlers>
              <add logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                name="Logging Handler" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>
Run Code Online (Sandbox Code Playgroud)

我发现了这个问题:在将企业库注册到GAC后无法解决类型运行时错误,但即使在更改fullName属性的版本段后,我的应用仍然表现相同.

sab*_*669 6

好吧,我能够找到一个使用Logging处理程序的示例应用程序.结果我需要一个参考ExceptionHandling.Logging:

Microsoft.Practices.EnterpriseLibrary.Common
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging ****
Microsoft.Practices.EnterpriseLibrary.Logging
Microsoft.Practices.ObjectBuilder2
Run Code Online (Sandbox Code Playgroud)

我在哪里只提到:

Microsoft.Practices.EnterpriseLibrary.Common
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Microsoft.Practices.EnterpriseLibrary.Logging
Microsoft.Practices.ObjectBuilder2
Run Code Online (Sandbox Code Playgroud)