title: Querying parallel foreach result cause Null reference error
body: <p>I have a parallel foreach statement like below </p>
  
  <pre><code>  Parallel.ForEach(spacialRecords, (spacerecord) =&gt;
                     {
                         List&lt;MeterValue&gt; dat = new List&lt;MeterValue&gt;();
                         var latitude = Geometry.Y;
                         var longitude = spacerecord.Geometry.X;
                         var timeStamp = spacerecord.Timestamp;
  
                         foreach (var wdItem in workingData)
                         {
                             RepresentationValue spaceMeteredValue = spacerecord.GetMeterValue(wdItem);
                             if (spaceMeteredValue != null &amp;&amp; wdItem.Representation != null)
                             {
                                 var objMeterValue = new MeterValue();
                                 objMeterValue.key = wdItem.Representation.Code;
                                 objMeterValue.value = spaceMeteredValue.Designator != null ? Convert.ToString(spaceMeteredValue.Designator) : "";
                                 dat.Add(objMeterValue);
                             }
                         }
  
                         listSpacialRecords.Add(new
                         {
  
                             operationLogDataId = yieldMaster.OperationalLogDataModelResponse.Id,
                             order = deviceElement.Order,
                             totalDistanceTravelled = deviceElement.TotalDistanceTravelled,
                             totalElapsedTime = deviceElement.TotalElapsedTime,
                             uploadedOn = DateTime.Now.ToUniversalTime(),
                             collectedOn = timeStamp.ToUniversalTime(),
                             cropId = "8296e610-c055-11e7-851e-ad7650a5f99c",
                             productId = productid,
                             latitude = latitude,
                             longitude = longitude,
                             deviceConfigurationId = deviceElement.DeviceConfigurationId,
                             operationDataId = deviceElement.OperationDataId,
                             spatialRecords = dat,
                             depth = depth,
                             timeStamp = timeStamp,
                             totaldata = totalRecordCount
  
                         });
  
                     });
  </code></pre>
  
  <p>listSpacialRecords is a dynamic type list and i am getting a huge number of data in listSpacialRecords. So here i am doing some filtering, for that i have added the below code </p>
  
  <pre><code> listSpacialRecords = listSpacialRecords
                    .Skip(1)
                    .Aggregate(
                        listSpacialRecords.Take(1).ToList(),
                        (a, x) =&gt;
                        {
                            if (x.timeStamp.Subtract(a.Last().timeStamp).TotalSeconds &gt;= 10.0)
                            {
                                a.Add(x);
                            }
                            return a;
                        });
  </code></pre>
  
  <p>The code is outside of foreach loop. And when i execute this I am getting error like </p>
  
  <pre><code>Cannot perform run time binding on a null reference
  </code></pre>
  
  <p>But when i remove the parallel and use normal foreach loop the code works fine. </p>
  
  <p>Note : I made a break point over and I found listSpacialRecords shows all the records properly, I have checked with quickwatch and upto last element data is available but still it fails</p>
  
  <p>Can anyone help me to figure out what i the issue?</p>