title: Source array was not long enough. Check srcIndex and length, and the array's lower bounds
body: <p>I have a C# list which will be added value in Parallel Foreach. Now it always returns exception System.IndexOutOfRangeException. When I pointed to the listTotalCost, it has the following message   </p>
  
  <blockquote>
    <p>Source array was not long enough. Check srcIndex and length, and the
    array's lower bounds.</p>
  </blockquote>
  
  <p>Is it caused by the thread safe problem and any other issue? Here is my code</p>
  
  <pre><code>List&lt;decimal&gt; listTotalCost = new List&lt;decimal&gt;();
  
  Parallel.ForEach(listDates, dates =&gt;
  {
      using (DataSet result = calculationMgr.EvaluateFormula(companyID, dates.startDate, dates.endDate, subIndicatorID.Value.ToString(), null, false, null
          , (int)Common.Systems.Sustainability.Constants.ApprovalStatuses.Approved
          ))
      {
          DataRow dr = result.Tables[0].Rows[0];
          //totalPrice = Convert.ToDecimal(dr["Result"]).ToString("#,##0.00");
          decimal? temp = Common.Util.TryToConvertToDecimal(dr, "Result");
          if (temp != null)
          {
              //the following line is the error happened 
              listTotalCost.Add(temp.Value);
          }
      }
  });
  </code></pre>