今天使用 Unity 编译出现一个错误, 最后解决了,做个记录。
error:
ArgumentException: Key duplication when adding: XXXSystem.Collections.Hashtable.PutImpl (System.Object key, System.Object value, Boolean overwrite) (at/Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections/Hashtable.cs:831)System.Collections.Hashtable.Add (System.Object key, System.Object value) (at/Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections/Hashtable.cs:474)如图:
出现这种情况的原因是,由两个并发请求引起的关键字重复添加错误。
(C#脚本)
// 这在定义的时候 直接初始化,就会出现这种情况。private static Hashtable hash = new Hashtable(); hash.Add("AA",AA);hash.Add("BB",BB);hash.Add("CC",CC);// 应该这样定义,定义hash 初始化为 null
private static Hashtable hash = nulll;// 在调用之前,再初始化:hash = new Hashtable(); // 每添加一行数据 ,初始化一次hash.Add("AA",AA);hash.Add("BB",BB);hash.Add("CC",CC);这样就可以解决这个错误了。(~ ̄▽ ̄)~
参考资料:
http://mono.1490590.n4.nabble.com/System-ArgumentException-Key-duplication-when-adding-httpModules-td4649636.html