I am getting this error in this line
Error Says:
system.invalidoperationexception collection was modified enumeration operation may not execute at System.Collections.Generic.Dictionary '2.ValueCollection.Enumerator.MoveNext<>
Line which I have error in
foreach (ISkill skill in client.Spells.Values)
When I tried to replace foreach
with for
I got three errors
UPDATE: My full code
public static void SaveSpells(GameState client)
{
if (client.Fake) return;
if (client.TransferedPlayer) return;
if (((client.Entity != null) && (client.Spells != null)) && (client.Spells.Count != 0))
{
foreach (ISkill skill in client.Spells.Values)
{
DeadPool.Database.MySqlCommand command;
if (skill.Available)
{
// if (skill.PreviousLevel != skill.Level)
{
command = new DeadPool.Database.MySqlCommand(MySqlCommandType.UPDATE);
command.Update("skills").Set("LevelHu2", skill.LevelHu2).Set("LevelHu", (long)skill.Souls).Set("Level", (long)skill.Level).Set("PreviousLevel", (long)skill.Level).Set("PreviousLevel", (long)skill.PreviousLevel).Set("Experience", (long)skill.Experience).Where("EntityID", (long)client.Entity.UID).And("ID", (long)skill.ID).Execute();
}
}
else
{
skill.Available = true;
command = new DeadPool.Database.MySqlCommand(MySqlCommandType.INSERT);
command.Insert("skills").Set("LevelHu2", skill.LevelHu2).Set("LevelHu2", skill.LevelHu2).Insert("LevelHu", (long)skill.Souls).Insert("Level", (long)skill.Level).Insert("PreviousLevel", (long)skill.Level).Insert("Experience", (long)skill.Experience).Insert("EntityID", (long)client.Entity.UID).Insert("ID", (long)skill.ID).Execute();
}
}
}
}