DependencyProperty重复注册引起的bug

这两天碰到一个非常奇怪的bug,在某些PC上都是正常的, 独在一台机上直接crash掉,有handler app exception也catch不到,出的是clr的错误(http://msdn.microsoft.com/en-us/magazine/cc793966.aspx 根本不知道所云),又不方便debug(在美国,我这边网络不太好,想remote debug很慢)。想了很久不知道什么原因。

最后只能让我老板(在美国)去DEBGU才发现有两个usercontrol1和usercontrol2 register dependency property都是一样的包括typeof 指向的都是同一个usercontrol1). 但是usercontrol2从来没有用到这个property, 而且两个usercontrol也不会同时加载在UI。我测试了一下如果同时使用在就会报错,但是不同时使用就不会。

最后我问他原因他是这样解释的: 

the sequence of static constructor is undefined

I think it's related to the loading of the machines and the memory consumption

and then CLR may decide to run it earlier

CLR may decide it doesn't need to run it at all

note that the problem is at usercontrol2 

which I never need

so, it's not surprised that CLR doesn't call the static constructor of usercontrol2 in your machine

if it doesn't call that static method, you won't have problem.

我想也是这样的原因,因为clr它在不同的PC上的内存管理不一样,会去决定预加载一些将会用到的组件,可能在有些PC上它会同时预加载usercontrol1和useronctro2,所以就会报错。但不管怎么说,我都觉得这应该是microsft的一个bug.

而且这样的问题以后很难在开发的过程中可以检查出来的。 

转载于:https://www.cnblogs.com/javak/archive/2010/10/29/1864318.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值