1
廣告我正在用C#開發一個項目我最近遇到了一個我無法理解的錯誤。IEquatable操作由於對象的當前狀態而無效
的一切都在這裏首先是核心
if (CanPlay(target.Coord.X, target.Coord.Y))
{
target.Owner = m.Player;
this.MoveList.Push(m);
// Groupes
var friends = GetAround(target).FindAll(i => i.Owner == target.Owner);
Groupe g = new Groupe { target };
foreach (Intersection fr in friends)
{
g.AddRange(GetGroupe(fr));
}
foreach (Intersection fr in friends)
{
this.Groupes.Remove(GetGroupe(fr));
}
this.Groupes.Add(g);
}
這裏是getGroupe功能引起該問題:
Groupe GetGroupe(Intersection i)
{
return this.Groupes.First(g => g.Contains(i));
}
因此,在一些隨機的時刻,當移動完成後,我由於對象的當前狀態,獲取IEquatable操作無效。 這裏是堆棧跟蹤:
InvalidOperationException: Operation is not valid due to the current state of the object
System.Linq.Enumerable.First[Groupe] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback)
System.Linq.Enumerable.First[Groupe] (IEnumerable`1 source, System.Func`2 predicate)
Assets.ObjetsDeJeu.Goban.GetGroupe (Assets.ObjetsDeJeu.Intersection i) (at Assets/ObjetsDeJeu/Goban.cs:155)
Assets.ObjetsDeJeu.Goban.PutRock (Assets.ObjetsDeJeu.Move m) (at Assets/ObjetsDeJeu/Goban.cs:142)
所以線142
g.AddRange(GetGroupe(fr));
和155
return this.Groupes.First(g => g.Contains(i));
我不明白,因爲this.Groupes只在空非常成功。我做了一個測試,在檢查組之前是否爲空但它沒有改變任何東西...
請提供'Groupe'和'Intersection'的定義 –