title: Linq to EF Join throws "Index was out of range" after upgrade from VS2010 to VS2012
body: <p>After upgrading from Visual Studio 2010 to 2012 code started throwing "ArgumentOutOfRangeException - Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index" on Linq queries using Joins.</p>
  
  <p>The following simple example made in LINQPad (using an EF data model) gives me the ArgumentOutOfRangeException:</p>
  
  <pre><code>void Main()
  {
      var iq1 = Customers.Select(ap =&gt; ap.ID);
      var iq2 = iq1.Join(Customers.Select(ap =&gt; ap.ID),
                      a =&gt; a,
                      b =&gt; b,
                      (a, b) =&gt; new { a });
  
      iq2.Dump(); 
  }
  </code></pre>
  
  <p>Changing the previous example to return an anonymous object containing both sides of the join doesn't give the ArgumentOutOfRangeException and gives results as expected:</p>
  
  <pre><code>void Main()
  {
      var iq1 = ActionPlans.Select(ap =&gt; ap.ID);
      var iq2 = iq1.Join(ActionPlans.Select(ap =&gt; ap.ID),
                      a =&gt; a,
                      b =&gt; b,
                      (a, b) =&gt; new { a, b });
  
      iq2.Dump(); 
  }
  </code></pre>
  
  <p>Ok, so for some reason I had to return both sides of the join, but then I tried the following example using a dummy value instead, that also executed without a problem:</p>
  
  <pre><code>void Main()
  {
      var iq1 = ActionPlans.Select(ap =&gt; ap.ID);
      var iq2 = iq1.Join(ActionPlans.Select(ap =&gt; ap.ID),
                      a =&gt; a,
                      b =&gt; b,
                      (a, b) =&gt; new { a, x = 1 });
  
      iq2.Dump(); 
  } 
  </code></pre>
  
  <p>Taking the first example and adding a ToList() to the first query also makes it execute without a problem:</p>
  
  <pre><code>void Main()
  {
      var iq1 = ActionPlans.Select(ap =&gt; ap.ID).ToList();
      var iq2 = iq1.Join(ActionPlans.Select(ap =&gt; ap.ID),
                      a =&gt; a,
                      b =&gt; b,
                      (a, b) =&gt; new { a });
  
      iq2.Dump(); 
  }
  </code></pre>
  
  <p><strong>Important:</strong> Trying the first query on a workstation without the Visual Studio 2012 upgrade works fine!</p>
  
  <p>Can anyone confirm/explain this new "feature"? :-)</p>