title: Application / Working Directory is not the same for the Design View and for the runtime application
body: <p>I am developing a C# Windows Presentation Foundation (WPF) application in Visual Studio 2010 Professional. I have a piece of code that finds a directory that is relative to the executable directory. I have some other code that searches that directory for all files ending in the extension .png and creates a list of full file paths to these files, which is data-bound to a ListBox.</p>
  
  <p>The program runs fine when it is executed in debug mode. The problem is that the Visual Studio design view cannot display the ListBox in the UserControl. In other words, it cannot create an instance of the UserControl as an “Exception has been thrown by the target of an invocation”. It turns out that the design view gets a different directory than the directory that the executable uses. Specifically the Visual Studio design view gets “C:\Documents and Settings\jdgoodw0\My Documents\Visual Studio 2010\Projects\ExampleDrawingTool” and the runtime application gets “C:\Documents and Settings\jdgoodw0\My Documents\Visual Studio 2010\Projects\ExampleDrawingTool\ExampleDrawingTool\bin\Debug”. (I know this because I put in some debug code to output the directories as arguments to an exception.)</p>
  
  <p>The code I used to get the application / working directory is:</p>
  
  <pre><code>DirectoryInfo currentDirectory = new DirectoryInfo(Environment.CurrentDirectory);
  </code></pre>
  
  <p>I have also tried these with no success:</p>
  
  <pre><code>DirectoryInfo currentDirectory = new DirectoryInfo(System.AppDomain.CurrentDomain.BaseDirectory);
  DirectoryInfo currentDirectory = new DirectoryInfo(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location));
  DirectoryInfo currentDirectory = new DirectoryInfo(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
  DirectoryInfo currentDirectory = new DirectoryInfo(System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName));
  </code></pre>
  
  <p>Is there a way that I can get the directory (full path) of the executable (i.e. in the bin\Debug folder) such that both the executable and the Visual Studio Design View will get the same path?</p>