EnterpriseLibrary Validation的配置导致AmbiguousMatchException问题
来源:互联网 发布:淘宝详情页制作步骤 编辑:程序博客网 时间:2024/05/13 00:59
前几天在用EL的Validation进行App.Config配置时遇到了比较头疼的情况: 在对隐藏父类成员(一般为属性)的子类成员进行配置时一切正常,但是在运行后就抛出了
System.Reflection.AmbiguousMatchException异常,查了EL的源码,发现源头出在了ValidationReflectionHelper类中的GetProperty方法中,如下:
在获取属性时仅考虑子类的成员即可。改完源码后需要对原程序集进行重新编译,可能还得添加强命名,并且对App配置文件中关于Validation段的设置都要进行修改,重新运行后问题解决。
System.Reflection.AmbiguousMatchException异常,查了EL的源码,发现源头出在了ValidationReflectionHelper类中的GetProperty方法中,如下:
internal static PropertyInfo GetProperty(Type type, string propertyName, bool throwIfInvalid) { if (string.IsNullOrEmpty(propertyName)) { throw new ArgumentNullException("propertyName"); } PropertyInfo propertyInfo = type.GetProperty(propertyName,BindingFlags.Public | BindingFlags.Instance); ...//省略 }
问题就出在红色标记处,因为在反射调用时父类和子类各有一个同名的属性,在运行时就会抛出匹配的异常,解决这个问题就只能改源码了:
... internal static PropertyInfo GetProperty(Type type, string propertyName, bool throwIfInvalid) { if (string.IsNullOrEmpty(propertyName)) { throw new ArgumentNullException("propertyName"); } PropertyInfo propertyInfo = null; try { propertyInfo = type.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance); } catch (AmbiguousMatchException ) { propertyInfo = type.GetProperty(propertyName, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); } ... return propertyInfo; }...
在获取属性时仅考虑子类的成员即可。改完源码后需要对原程序集进行重新编译,可能还得添加强命名,并且对App配置文件中关于Validation段的设置都要进行修改,重新运行后问题解决。
- EnterpriseLibrary Validation的配置导致AmbiguousMatchException问题
- 配置struts validation遇到的一些问题
- EnterpriseLibrary的DAAB如何灵活配置数据库的笔记
- validation.xml的配置
- validation.xml的配置
- springmvc4的validation配置
- 解决struts2中validation.xml配置无效的问题
- 一个struts配置导致的问题
- 网卡配置导致的网络性能问题
- 数据库默认安装配置导致的问题
- php配置导致的页面编码问题
- eclipse 简单的validation配置
- 发现springmodules validation的问题
- JQuery Validation插件的问题
- Struts2 的validation.xml验证配置
- Extjs 导入开发包报错的validation 配置
- SELinux导致的samba匿名访问配置问题
- SELinux导致的Samba匿名访问配置问题
- iOS安全攻防(一):Hack必备的命令与工具
- Tcp/Ip协议基础
- Android应用程序的四个关键点
- 【Sencha Touch 2】SenchaTouch程序编译和打包
- struts2教程:15、自定义拦截器
- EnterpriseLibrary Validation的配置导致AmbiguousMatchException问题
- Linux下静态库,动态库的创建和使用,多个动态库使用
- 线程的挂起和唤醒
- for循环
- STM32之将V3.5的固件库制成lib静态库
- lvm使用
- iOS开发记录(7)
- 人生哲理---人的一生
- C++实现系统服务暂停、停止、启动