Calling LINQ First() or Single() on an empty collection.
Occurs when attempting to retrieve the first or single element from an empty LINQ collection using `.First()` or `.Single()`.
Executing `.First()` or `.Single()` on a collection where zero items match the filtering predicate.
1using System;2using System.Collections.Generic;3using System.Linq;4 5public class Program {6 public static void Main() {7 List<int> numbers = new List<int> { 1, 3, 5 };8 int even = numbers.First(n => n % 2 == 0); // InvalidOperationException: Sequence contains no elements9 }10}1using System;2using System.Collections.Generic;3using System.Linq;4 5public class Program {6 public static void Main() {7 List<int> numbers = new List<int> { 1, 3, 5 };8 9 // Fix: Use FirstOrDefault() instead of First()10 int even = numbers.FirstOrDefault(n => n % 2 == 0); // Returns 0 (default int)11 Console.WriteLine($"First even number: {even}");12 }13}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
None of the numbers match `n % 2 == 0`. `.First()` requires at least one matching item and throws `InvalidOperationException` when empty.