title: C# read each line from text file and update label with each line
body: <p>I have a C# program that should be iterating through a log file, line by line, and then updating a label based on what it reads, however, I get an unhandled exception.</p>
  <p>The file that it is reading from is coming from another external c++ program that is writing to the log (I want this C# wrapper program to be able to redirect output from the text to this window (and the only way I could think of was to read from the log from c# as the c++ program wrote to the log.</p>
  <p>Here is the code:</p>
  <pre><code>p = new Process();
  p.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + &quot;\\scan.cmd&quot;;
  p.Start();
  //p.WaitForExit();
  // Read the file and display it line by line.
  string logFile = AppDomain.CurrentDomain.BaseDirectory + &quot;\\log.txt&quot;;
  string line;
  System.IO.StreamReader file = new System.IO.StreamReader(logFile);
  while((line = file.ReadLine()) != null &amp;&amp; p.HasExited == false)
  {
     itemBeiingScanned_Label.Content = line;
  }
  
  file.Close();
  </code></pre>
  <p>And here is the exception (occurs twice)-</p>
  <blockquote>
  <p>A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll</p>
  <p>Additional information: The invocation of the constructor on type 'SpywareKing.MainWindow' that matches the specified binding constraints threw an exception.</p>
  <p>If there is a handler for this exception, the program may be safely continued.</p>
  </blockquote>
  <p>And here is the debug code:</p>
  <pre><code>64e35\PresentationFramework.dll'. Symbols loaded.
  The thread 0x20c0 has exited with code 259 (0x103).
  The thread 0x13b0 has exited with code 0 (0x0).
  The thread 0x383c has exited with code 0 (0x0).
  The thread 0x2838 has exited with code 259 (0x103).
  'SpywareKing.vshost.exe' (CLR v4.0.30319: SpywareKing.vshost.exe): Loaded     'C:\Users\Jaycen\Documents\Dev\SpywareKing\SpywareKing\bin\x64\Release\SpywareKing.exe'.     Symbols loaded.
  'SpywareKing.vshost.exe' (CLR v4.0.30319: SpywareKing.vshost.exe): Loaded     'C:\windows\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Acc    essibility.dll'. Symbols loaded.
  SpywareKing.vshost.exe' (CLR v4.0.30319: SpywareKing.vshost.exe): Loaded     C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Symbols loaded.
  'SpywareKing.vshost.exe' (CLR v4.0.30319: SpywareKing.vshost.exe): Loaded     'C:\windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Aero2\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Aero2.dll'. Symbols loaded.
  A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll
  A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
  A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
  A first chance exception of type 'System.Xaml.XamlObjectWriterException' occurred in System.Xaml.dll
  A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
  Additional information: The invocation of the constructor on type     'SpywareKing.MainWindow' that matches the specified binding constraints threw an exception.
  
  An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
  Additional information: The invocation of the constructor on type 'SpywareKing.MainWindow' that matches the specified binding constraints threw an exception.
  
  The program '[14348] SpywareKing.vshost.exe' has exited with code 0 (0x0).
  </code></pre>