This question was 
             closed May 08, 2017 at 11:03 AM by 
             Alex19998282 for the following reason: 
             
 
            Problem is not reproducible or outdated
 
               Question by 
               Alex19998282 · May 08, 2017 at 01:28 AM · 
                c#unity 5scripting problempathfindinglinq  
              
 
              InvalidOperationException thrown
I'm having issues with the following code, which is throwing an Invalid Operation Exception
             if (nodeToAdd.nodeCoord != AStarSets.closedSet.First(a => a.nodeCoord == nodeToAdd.nodeCoord).nodeCoord)
             {
                 if (nodeToAdd.nodeCoord == AStarSets.openSet.First(a => a.nodeCoord == nodeToAdd.nodeCoord).nodeCoord)
                 {
                     if (currentHex.GetComponent<HexObject>().hexObjectValuesOut.gValue > Math.Abs(((int)nodeToAdd.nodeCoord.x - x) + ((int)nodeToAdd.nodeCoord.y - y)))
                     {
                         getGCost(nodeToAdd.nodeCoord);
                         currentHex.GetComponent<HexObject>().hexObjectValuesOut.setFValue();
                         nodeToAdd.nodeCost = currentHex.GetComponent<HexObject>().hexObjectValuesOut.fValue;
                         nodeToAdd.parentNode = parentNode;
 
                         AStarSets.openSet.Add(nodeToAdd);
                     }
                 }
             }
 
               This code throws the following exception:
 InvalidOperationException: Operation is not valid due to the current state of the object
 System.Linq.Enumerable.First[AStarNodes] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback)
 System.Linq.Enumerable.First[AStarNodes] (IEnumerable`1 source, System.Func`2 predicate)
 InfantryPathfinding.addNode (.AStarNodes nodeToAdd, .AStarNodes parentNode, Int32 x, Int32 y, UnityEngine.GameObject currentHex) (at Assets/Hex Grid/Test/InfantryPathfinding.cs:220)
 InfantryPathfinding+<getAboveAndBelowHexes>c__Iterator4.MoveNext () (at Assets/Hex Grid/Test/InfantryPathfinding.cs:210)
 UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
 
               Any help will be much appreciated
               Comment
              
 
               
              Follow this Question
Related Questions
How attach C# script by argument? 3 Answers
Turning Off Tag After Collision 0 Answers
uNet. Spawning objects over the network. 0 Answers
my camera is rotating on Z axis when i just set it on X and Y 0 Answers
use a function twice 1 Answer