最后只能让我老板(在美国)去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.
而且这样的问题以后很难在开发的过程中可以检查出来的。