0

I'm within a block of code... and when I call this method: File.ReadAllLines(string filepath)

The program breaks out of the codeblock and everything after that line doesn't get run. What is going on? I've messed around with the Dispose() method and added a condition... but nothing has worked.

LarsTech
  • 80,625
  • 14
  • 153
  • 225
rikkitikkitumbo
  • 954
  • 3
  • 17
  • 38

1 Answers1

2

It sounds like some type of exception is being thrown and causing the program to exit (perhaps the file location is incorrect).

You'll probably want to use a try-catch block and wrap your ReadAllLines() call so that you can capture the exception and see exactly what is going wrong :

try
{
      File.ReadAllLines(yourPath)
}
catch(Exception ex)
{
      // Place a breakpoint here to look at the exception
      Console.WriteLine(ex.Message);
}

Try using the Visual Studio debugger to run your application in Debug mode to see if the exception message sheds any insight into your issue. You can also check the Event Viewer to see if any stack traces or other errors are present there as well.

Rion Williams
  • 74,820
  • 37
  • 200
  • 327