0

This is my code , but my code seems to be exiting without printing anything onto the console:

string s_Item = "Error 500";

var lines = File.ReadLines("C:/Users/lenovo/Desktop/Probablisitic Automata/data/April/april_steady_state.csv");

foreach (string line in lines)
{
    if (line.Contains(s_Item))
    {
        Console.WriteLine(line);
    }

}

I get the following error :

'Read_april_csv.vshost.exe' (CLR v4.0.30319: Read_april_csv.vshost.exe): Loaded 'c:\users\lenovo\documents\visual studio 2015\Projects\Read_april_csv\Read_april_csv\bin\Debug\Read_april_csv.exe'. Symbols loaded. The thread 0x2878 has exited with code 0 (0x0). The thread 0x3ed8 has exited with code 0 (0x0). The program '[13288] Read_april_csv.vshost.exe' has exited with code 0 (0x0).

Steve
  • 213,761
  • 22
  • 232
  • 286
Kira
  • 483
  • 1
  • 4
  • 10
  • Are you sure that any other app is not using this file? – Dominik S May 09 '16 at 09:28
  • 2
    These are not error messages but only diagnostics messages emitted during the debug session. Are you sure that your file contains the string searched? As usual, use the debugger to see if your code runs as intendend – Steve May 09 '16 at 09:31
  • What happens when you debug the code ? Does it reach the the lines `foreach` ? Does it get past the `ReadLines` statement ? From the code sample there is no exception you could get, in normal conditions, unless the file could not be opened (for instance, if it is opened by some other process). The `Contains` method searching for a non existent string will not throw an error. – Veverke May 09 '16 at 09:39
  • Comment out the if statement, and just print out using `Console.WriteLine` the contents of the file to make sure it's not empty. If it's not empty, make sure a line does contain the string `Error 500`. Also, have you made sure to put a `Console.ReadLine()` to stop the console window from closing when this has executed? – TEK May 09 '16 at 09:40
  • Thanks for all your comments @TEK, i did comment out the if statement and added a readline , which displays only the headers but not the values in the csv file , do i need to add something for the delimiters ',' ? any help appreciated, thanks once again – Kira May 09 '16 at 10:15

0 Answers0