Reputation: 3
Here is the code I am working with:
p = new Process();
p.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "\\scan.cmd";
p.Start();
p.WaitForExit();
// Read the file and display it line by line.
string line;
System.IO.StreamReader file = new System.IO.StreamReader("\\log.txt");
while((line = file.ReadLine()) != null)
{
itemBeiingScanned_Label.Content = line;
}
file.Close();
When building it runs everything up until this point and then throws two identically worded unhanded exception's:
Exception:
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.
If there is a handler for this exception, the program may be safely continued.
Any insight would be appreciated-- I can provide more information if there is something that you need to help with looking into the root of the problem.
Here is some potentially useful information from the debug console in Visual Studio:
'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.FileNotFoundException' 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.
The thread 0x33dc has exited with code 0 (0x0). 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 '[13492] SpywareKing.vshost.exe' has exited with code 0 (0x0).
Upvotes: 0
Views: 917
Reputation: 112259
Most probably the line
System.IO.StreamReader file = new System.IO.StreamReader("\\log.txt");
is the cause of the error. You cannot safely assume that the current directory is the one where the log file resides. Always specify the full path.
string logFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt")
System.IO.StreamReader file = new System.IO.StreamReader(logFie);
The current directory can change at any time when the user is selecting a directory in a FileOpenDialog or FileSaveDialog. It's not automatically the applications directory. Also the applications directory will be \SolutionFolder\ProjectFolder\bin\Debug
when debugging. Is this the directory you are looking for?
Upvotes: 0