System.InvalidOperationException in Output Window
<p>I constantly get the following message in my output/debug windows. The app doesn't crash but I was wondering what the deal with it is:</p>

<p>A first chance exception of type 'System.InvalidOperationException' occurred in System.dll</p>

<p>my code :sol.cs</p>

<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Sol
    {


        public LinkedList&lt;int&gt; tower1 = new LinkedList&lt;int&gt;();
        public LinkedList&lt;int&gt; tower2 = new LinkedList&lt;int&gt;();
        public LinkedList&lt;int&gt; tower3 = new LinkedList&lt;int&gt;();

        public static LinkedList&lt;string&gt; BFS = new LinkedList&lt;string&gt;();
        public static LinkedList&lt;string&gt; DFS = new LinkedList&lt;string&gt;();
        public static LinkedList&lt;string&gt; IDS = new LinkedList&lt;string&gt;();


        public int depth;

        public LinkedList&lt;Sol&gt; neighbors;

        public Sol()
        {
        }

        public Sol(LinkedList&lt;int&gt; tower1, LinkedList&lt;int&gt; tower2, LinkedList&lt;int&gt; tower3)
        {
            this.tower1 = tower1;
            this.tower2 = tower2;
            this.tower3 = tower3;

            neighbors = new LinkedList&lt;Sol&gt;();
        }

        public virtual void getneighbors()
        {

            Sol temp = this.copy();
            Sol neighbor1 = this.copy();
            Sol neighbor2 = this.copy();
            Sol neighbor3 = this.copy();
            Sol neighbor4 = this.copy();
            Sol neighbor5 = this.copy();
            Sol neighbor6 = this.copy();





            if (temp.tower1.Count != 0)
            {

                if (neighbor1.tower2.Count != 0)
                {
                    if (neighbor1.tower1.First.Value &lt; neighbor1.tower2.First.Value)
                    {
                        neighbor1.tower2.AddFirst(neighbor1.tower1.First);
                        neighbor1.tower1.RemoveFirst();
                        neighbors.AddLast(neighbor1);
                    }

                }
                else
                {
                    neighbor1.tower2.AddFirst(neighbor1.tower1.First);
                    neighbor1.tower1.RemoveFirst();
                    neighbors.AddLast(neighbor1);
                }



                if (neighbor2.tower3.Count != 0)
                {
                    if (neighbor2.tower1.First.Value &lt; neighbor2.tower3.First.Value)
                    {
                        neighbor2.tower3.AddFirst(neighbor2.tower1.First);
                        neighbor2.tower1.RemoveFirst();
                        neighbors.AddLast(neighbor2);
                    }
                }
                else
                {
                    neighbor2.tower3.AddFirst(neighbor2.tower1.First);
                    neighbor2.tower1.RemoveFirst();
                    neighbors.AddLast(neighbor2);
                }

            }




            //-------------

            if (temp.tower2.Count != 0)
            {


                if (neighbor3.tower1.Count != 0)
                {
                    if (neighbor3.tower2.First.Value &lt; neighbor3.tower1.First.Value)
                    {
                        neighbor3.tower1.AddFirst(neighbor3.tower2.First);
                        neighbor3.tower2.RemoveFirst();
                        neighbors.AddLast(neighbor3);
                    }
                }
                else
                {
                    neighbor3.tower1.AddFirst(neighbor3.tower2.First);
                    neighbor3.tower2.RemoveFirst();
                    neighbors.AddLast(neighbor3);
                }



                if (neighbor4.tower3.Count != 0)
                {
                    if (neighbor4.tower2.First.Value &lt; neighbor4.tower3.First.Value)
                    {
                        neighbor4.tower3.AddFirst(neighbor4.tower2.First);
                        neighbor4.tower2.RemoveFirst();
                        neighbors.AddLast(neighbor4);
                    }
                }
                else
                {
                    neighbor4.tower3.AddFirst(neighbor4.tower2.First);
                    neighbor4.tower2.RemoveFirst();
                    neighbors.AddLast(neighbor4);
                }


            }


            //------------------------

            if (temp.tower3.Count() != 0)
            {


                if (neighbor5.tower1.Count() != 0)
                {
                    if (neighbor5.tower3.ElementAtOrDefault(0) &lt; neighbor5.tower1.ElementAtOrDefault(0))
                    {
                        neighbor5.tower1.AddFirst(neighbor5.tower3.First);
                        neighbor5.tower3.RemoveFirst();
                        neighbors.AddLast(neighbor5);
                    }
                }
                else
                {
                    neighbor5.tower1.AddFirst(neighbor5.tower3.First);
                    neighbor5.tower3.RemoveFirst();
                    neighbors.AddLast(neighbor5);
                }



                if (neighbor6.tower2.Count() != 0)
                {
                    if (neighbor6.tower3.ElementAtOrDefault(0) &lt; neighbor6.tower2.ElementAtOrDefault(0))
                    {
                        neighbor6.tower2.AddFirst(neighbor6.tower3.First);
                        neighbor6.tower3.RemoveFirst();
                        neighbors.AddLast(neighbor6);
                    }
                }
                else
                {
                    neighbor6.tower2.AddFirst(neighbor6.tower3.First);
                    neighbor6.tower3.RemoveFirst();
                    neighbors.AddLast(neighbor6);
                }

            }
        }

        public override string ToString()
        {

            string str;

            str = "tower1" + tower1.ToString() + "   tower2" + tower2.ToString() + "   tower3" + tower3.ToString();


            return str;

        }


        public Sol copy()
        {

            Sol So;
            LinkedList&lt;int&gt; l1 = new LinkedList&lt;int&gt;();
            LinkedList&lt;int&gt; l2 = new LinkedList&lt;int&gt;();
            LinkedList&lt;int&gt; l3 = new LinkedList&lt;int&gt;();


            for (int i = 0; i &lt;= this.tower1.Count() - 1; i++)
            {

                l1.AddLast(tower1.ElementAt(i));

            }



            for (int i = 0; i &lt;= this.tower2.Count - 1; i++)
            {

                l2.AddLast(tower2.ElementAt(i));

            }

            for (int i = 0; i &lt;= this.tower3.Count - 1; i++)
            {

                l3.AddLast(tower3.ElementAt(i));

            }


            So = new Sol(l1, l2, l3);
            return So;

        }



        public bool Equals(Sol sol)
        {

            if (this.tower1.Equals(sol.tower1) &amp; this.tower2.Equals(sol.tower2) &amp; this.tower3.Equals(sol.tower3))
                return true;

            return false;

        }


        public virtual bool containedin(Stack&lt;Sol&gt; vec)
        {

            bool found = false;

            for (int i = 0; i &lt;= vec.Count - 1; i++)
            {
                if (vec.ElementAt(i).tower1.Equals(this.tower1) &amp;&amp; vec.ElementAt(i).tower2.Equals(this.tower2) &amp;&amp; vec.ElementAt(i).tower3.Equals(this.tower3))
                {
                    found = true;
                    break;
                }

            }

            return found;
        }




        public virtual bool breadthFirst(Sol start, Sol goal)
        {
            Stack&lt;Sol&gt; nextStack = new Stack&lt;Sol&gt;();
            Stack&lt;Sol&gt; traversed = new Stack&lt;Sol&gt;();
            bool found = false;

            start.depth = 0;
            nextStack.Push(start);


            while (nextStack.Count != 0)
            {


                Sol sol = nextStack.Pop();

                BFS.AddFirst("poped State:" + sol.ToString() + "level " + sol.depth);

                traversed.Push(sol);

                if (sol.Equals(goal))
                {
                    found = true;
                    BFS.AddFirst("Goal:" + sol.ToString());

                    break;
                }

                else
                {

                    sol.getneighbors();

                    foreach (Sol neighbor in sol.neighbors)
                    {

                        if (!neighbor.containedin(traversed) &amp;&amp; !neighbor.containedin(nextStack))
                        {
                            neighbor.depth = (sol.depth + 1);
                            nextStack.Push(neighbor);
                        }
                    }
                }
            }

            return found;
        }


        public virtual bool depthFirst(Sol start, Sol goal)
        {
            Stack&lt;Sol&gt; nextStack = new Stack&lt;Sol&gt;();
            Stack&lt;Sol&gt; traversed = new Stack&lt;Sol&gt;();

            bool found = false;

            start.depth = 0;
            nextStack.Push(start);

            while (nextStack.Count != 0)
            {
                //Dequeue next State for comparison
                //And add it 2 list of traversed States
                Sol sol = nextStack.Pop();


                DFS.AddFirst("poped State:" + sol.ToString() + "level " + sol.depth);


                traversed.Push(sol);


                if (sol.Equals(goal))
                {
                    found = true;
                    DFS.AddFirst("Goal:" + sol.ToString());
                    break;
                }
                else
                {

                    sol.getneighbors();
                    foreach (Sol neighbor in sol.neighbors)
                    {
                        if (!neighbor.containedin(traversed) &amp;&amp; !neighbor.containedin(nextStack))
                        {
                            neighbor.depth = sol.depth + 1;
                            nextStack.Push(neighbor);
                        }



                    }
                }

            }
            return found;
        }


        public virtual bool iterativedeepening(Sol start, Sol goal)
        {
            bool found = false;




            for (int level = 0; ; level++)
            {

                Stack&lt;Sol&gt; nextStack = new Stack&lt;Sol&gt;();
                Stack&lt;Sol&gt; traversed = new Stack&lt;Sol&gt;();


                start.depth = 0;
                nextStack.Push(start);

                while (nextStack.Count != 0)
                {

                    Sol sol = nextStack.Pop();

                    IDS.AddFirst("poped State:" + sol.ToString() + "Level" + sol.depth);

                    traversed.Push(sol);

                    if (sol.Equals(goal))
                    {
                        found = true;
                        IDS.AddFirst("Goal:" + sol.ToString());

                        break;
                    }
                    else if (sol.depth &lt; level)
                    {
                        sol.getneighbors();
                        foreach (Sol neighbor in sol.neighbors)
                        {
                            if (!neighbor.containedin(traversed) &amp;&amp; !neighbor.containedin(nextStack))
                            {
                                neighbor.depth = sol.depth + 1;
                                nextStack.Push(neighbor);
                            } //end if
                        } //end for each

                    } //end else if
                } // end while

                if (found == true)
                    break;
            } // end for
            return found;
        }



    }
}
</code></pre>

<p>Just wondering if I may be doing something wrong somewhere or something. >>></p>
