企业库学习:异常处理模块

来源:互联网 发布:选数码产品软件 编辑:程序博客网 时间:2024/05/01 12:20

微软企业库的使命:解决重复性设计。

目前5.1版本包括9大块内容:ogging, validation, caching, exception management.....

话不多说,我们看一下其中的异常处理机制(exception management)。

异常处理模块是做什么事的?

总结了一下:

1. 记录异常。

2. 封装、转发异常,给用户以友好提示。

3. 保护敏感信息。

怎么使用异处理模块?

一 配置.config文件,可手写也可使用配置工具,查查文档就可以了。给出配置后.config文件如下:

二 引用需要的dll。

三 写测试demo.

1. 获取ExceptionManager 实例

2. 捕获一个异常

3. 处理异常。

4. 使用

 

 

使用:找个页面,加行代码:Response.Write(ExceptionHandling.Test());

遇到的问题:

一、

创建 exceptionHandling 的配置节处理程序时出错: 未能加载文件或程序集“Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。

 

去:http://entlib.codeplex.com/wikipage?title=Why%20am%20I%20getting%20the%20messages%2c%20%22Could%20not%20load%20file%20or%20assembly%22&referringTitle=EntLib%20FAQ

 

关于企业库的常用错误,下面有相关资料:

 

http://entlib.codeplex.com/wikipage?title=EntLib%20FAQ&referringTitle=Home

 

”This typically occurs when the assembly-qualified names for Enterprise Library types in an application's configuration file do not match the identities of the assemblies deployed with the application. This situation can happen when the configuration files are authored with a version of the Enterprise Library configuration tool that does not match the assemblies referenced by the application; “

  大致说:原因是应用程序引用的(企业库)类名称与配置文件不符;一般是配置工具配置生成的.config文件中的程序集引用(引用的是强命名文件)和实现引用的程序集不匹配。和前面说的是一件事,又找了会:http://blogs.msdn.com/b/tomholl/archive/2007/04/19/avoiding-configuration-pitfalls-with-incompatible-copies-of-enterprise-library.aspx。

 

说:配置工具指向的默认程序集安装企业库的地方(C:/Program Files/Microsoft Enterprise Library 5.0/Bin),而实现引用的程序集是源码编译过的。这两份程序集是不匹配的。

 

1. 我将所有的dll文件从"C:/Program Files/Microsoft Enterprise Library 5.0/Bin")拷一遍,然后再重新引用,问题暂时性解决。

 

 

对问题进行深入分析:

  说白了,是配置工具引用了强命名dll文件,而具体程序中引用的dll与配置工具中的文件不符,从而产生的问题。

 

 

怎么避免呢?

  可参参照文章Avoiding configuration pitfalls with incompatible copies of Enterprise Library(http://blogs.msdn.com/b/tomholl/archive/2007/04/19/avoiding-configuration-pitfalls-with-incompatible-copies-of-enterprise-library.aspx)

  

下一篇:异常处理深入研究。

 

 

 

原创粉丝点击