title: CS1674 'IEnumerator': type used in a using statement must be implicitly convertible to 'System.IDisposable'
body: <p>I have to maintain an old project in my company which is coded using C# and old .NET Framework (maybe 2.0?) many years ago. I loaded old source files to Visual Studio and it gives me an error: "<strong>CS1674 'IEnumerator': type used in a using statement must be implicitly convertible to 'System.IDisposable'</strong>" when I try to build it. </p>
  
  <p>Here's a complete function which causes this error, most importantly this part: "<strong>using (IEnumerator enumerator = dataTable.Rows.GetEnumerator())</strong>", any advice how to get rid of it? </p>
  
  <p>I tried to read other similar questions but I could not solve this with them. Is there maybe alternative way to code this, or could my programming environment be a cause for this?</p>
  
  <pre><code>    public void CompileDynamicCode()
      {
          base.Session.trace_enter();
          try
          {
              try
              {
                  DataTable dataTable = this.ChimneyTable;
                  if (dataTable.Rows.Count &gt; 0)
                  {
                      this.oChimneys = new Chimney[dataTable.Rows.Count];
                      int num = 0;
  
                      using (IEnumerator enumerator = dataTable.Rows.GetEnumerator())
                      {
                          while (enumerator.MoveNext())
                          {
                              DataRow dataRow = (DataRow)enumerator.Current;
                              bool entryXRight = false;
                              bool posXRight = false;
                              bool calcSteps = true;
                              bool calcCatwalk = true;
                              bool calcPlatform = true;
                              bool calcFlashing = true;
                              int connectCatwalkTo = -1;
                              if ((int)dataRow["entryXFromRight"] == 1)
                              {
                                  entryXRight = true;
                              }
                              if ((int)dataRow["posXFromRight"] == 1)
                              {
                                  posXRight = true;
                              }
                              if (dataTable.Columns.Contains("calcSteps") &amp;&amp; (int)dataRow["calcSteps"] == 0)
                              {
                                  calcSteps = false;
                              }
                              if (dataTable.Columns.Contains("calcCatwalk") &amp;&amp; (int)dataRow["calcCatwalk"] == 0)
                              {
                                  calcCatwalk = false;
                              }
                              if (dataTable.Columns.Contains("calcPlatform") &amp;&amp; (int)dataRow["calcPlatform"] == 0)
                              {
                                  calcPlatform = false;
                              }
                              if (dataTable.Columns.Contains("calcFlashing") &amp;&amp; (int)dataRow["calcFlashing"] == 0)
                              {
                                  calcFlashing = false;
                              }
                              if (dataTable.Columns.Contains("catwalkConnection"))
                              {
                                  connectCatwalkTo = (int)dataRow["catwalkConnection"];
                              }
                              this.oChimneys[num] = new Chimney((int)dataRow["index"], (int)dataRow["shape_index"], (int)dataRow["entry_shape_index"], (int)dataRow["entryX"], entryXRight, (int)dataRow["posX"], posXRight, (int)dataRow["posY"], (int)dataRow["sizeX"], (int)dataRow["sizeY"], (int)dataRow["sizeZ"], (ChimneyAccessTypeEnum)dataRow["access_type"], calcSteps, calcCatwalk, calcPlatform, calcFlashing, connectCatwalkTo, this);
                              num++;
                          }
                          goto IL_247;
                      }
                  }
                  this.oChimneys = new Chimney[0];
                  IL_247:
                  dataTable = this.ShapeTable;
                  if (dataTable.Rows.Count &gt; 0)
                  {
                      this.oShapes = new BasicShape[dataTable.Rows.Count];
                      int num2 = 0;
                      foreach (DataRow dataRow2 in dataTable.Rows)
                      {
                          this.oShapes[num2] = new BasicShape((TopRowModeEnum)dataRow2["TopRowMode"], (EaveRowModeEnum)dataRow2["EaveRowMode"], (ShapeBehaviorEnum)dataRow2["Behavior"], num2, this);
                          num2++;
                      }
                  }
                  dataTable = this.ConnectorTable;
                  if (dataTable.Rows.Count &gt; 0)
                  {
                      this.oConnectors = new Connector[dataTable.Rows.Count];
                      int num3 = 0;
                      foreach (DataRow dataRow3 in dataTable.Rows)
                      {
                          BasicShape selectShape = null;
                          BasicShape selectShape2 = null;
                          try
                          {
                              selectShape = this.oShapes[(int)dataRow3["Shape1Index"]];
                          }
                          catch
                          {
                          }
                          try
                          {
                              selectShape2 = this.oShapes[(int)dataRow3["Shape2Index"]];
                          }
                          catch
                          {
                          }
                          this.oConnectors[num3] = new Connector((ConnectorBehaviorEnum)dataRow3["ConnectorBehavior"], selectShape, selectShape2, (ShapeConnectingLineEnum)dataRow3["Shape1Line"], (ShapeConnectingLineEnum)dataRow3["Shape2Line"], this, num3, (ConnectorStartEndMode)dataRow3["StartMode"], (ConnectorStartEndMode)dataRow3["StopMode"]);
                          num3++;
                      }
                  }
              }
              catch (Exception ex)
              {
                  base.Session.HandleException(ex);
                  throw ex;
              }
              this.DynamicObject = this.CreateFromScript();
          }
          catch (Exception ex2)
          {
              base.Session.HandleException(ex2);
              throw ex2;
          }
          finally
          {
              base.Session.trace_exit();
          }
      }
  </code></pre>