title: Sequence contains no matching element error in Linq Statement
body: <p>I am trying to debug my method but I don't know what's wrong with it. </p>
  
  <p>There are times that it throws an error and sometime it's okay. I don't know what's wrong. </p>
  
  <p>Here's my method: </p>
  
  <pre><code>private void GetWorkingWeek(int month, int year)
      {
          var cal = System.Globalization.CultureInfo.CurrentCulture.Calendar;
  
  
          var daysInMonth = Enumerable.Range(1, cal.GetDaysInMonth(year, month));
  
          var listOfWorkWeeks = daysInMonth
              .Select(day =&gt; new DateTime(year, month, day))
              .GroupBy(d =&gt; cal.GetWeekOfYear(d, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday))
              .Select(g =&gt; Tuple.Create(g.Key, g.First(), g.Last(d =&gt; d.DayOfWeek != DayOfWeek.Saturday &amp;&amp; d.DayOfWeek != DayOfWeek.Sunday)))
              .ToList();
           foreach (var weekGroup in listOfWorkWeeks)
                  {
                      Console.WriteLine("Week{0} = {1} {2} to {1} {3}"
                          , weekNum++
                          , System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month)
                          , weekGroup.Item2.Day
                          , weekGroup.Item3.Day);
                  }
      }
  </code></pre>
  
  <p>This is the line where the error appear:</p>
  
  <pre><code>var listOfWorkWeeks = daysInMonth
              .Select(day =&gt; new DateTime(year, month, day))
              .GroupBy(d =&gt; cal.GetWeekOfYear(d, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday))
              .Select(g =&gt; Tuple.Create(g.Key, g.First(), g.Last(d =&gt; d.DayOfWeek != DayOfWeek.Saturday &amp;&amp; d.DayOfWeek != DayOfWeek.Sunday)))
              .ToList();
  </code></pre>
  
  <p>This is the error: </p>
  
  <pre><code> InvalidOperationException : Sequence contains no matching element
  </code></pre>