// This won't work: Process proc = new Process(); string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase); proc.StartInfo.Filename = System.IO.Path.Combine(path, "myApp.exe"); proc.Start(); proc.WaitForExit(); // <-- Will crash here // This does work: Process proc = new Process(); proc.StartInfo.Filename = "myApp.exe"; proc.Start(); proc.WaitForExit();
Both samples will start myApp.exe just fine, but the first one seems to have some problems with Windows. Cost me four precious hours of my life.
btw, can anyone tell me why “new” in the code snippet above links to a google search for new and msdn.microsoft.com? No? That figures.

5 comments
Comments feed for this article
Trackback link
http://www.stopbeingcarbon.com/2007/10/love-hate-whatever/trackback/
October 21, 2007 at 18:13
Benedikt
Hmmm, isn’t there something wrong with your first example?
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase));Why are there two closing brackets after “CodeBase”?
October 21, 2007 at 18:14
Benedikt
Okay, now you can see it better:
System.IO.Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly().CodeBase));October 22, 2007 at 6:29
Christoph
You’re completely right. Thanks for the hint, changed the code.
October 22, 2007 at 11:24
Benedikt
But that’s not what was causing the original error?
October 22, 2007 at 16:58
Christoph
No, that would have been a compile time error. Mine was a little bit more tricky.