Had got this error in my program. Came across a few posts which kind of gave me the idea that this issue is probably due to file size. As far as my program is concerned, the observation I find is for small file sizes I do not get this error. For a relatively larger one this error crops up.
So this post kind of gave me the idea about how to replicate it.
I tried it below with another piece of code:
var filePath = @"C:\tools\sample_extract.csv";
var li = File.ReadLines(filePath);
for (int i = 0; i < 10; i++)
{
Console.WriteLine("Loop Count: {0}", i);
foreach (string k in li) ;
Thread.Sleep(1000);
}
Console.WriteLine("end");
Console.ReadLine();
However, I couldn't raise the exception.