title: How to avoid a Win32 exception when accessing Process.MainModule.FileName in C#?
body: <p>I started a new project listing the full paths to all running processes. When accessing some of the processes the program crashes and throws a <strong>Win32Exception</strong>. The description says an error occured while listing the process modules. Initially I thought this problem might occur because I'm running it on a <strong>64-bit</strong> platform, so I recompiled it for the CPU types <strong>x86</strong> and <strong>AnyCPU</strong>. I'm getting the same error, though.</p>
  
  <pre><code>Process p = Process.GetProcessById(2011);
  string s = proc_by_id.MainModule.FileName;
  </code></pre>
  
  <p>The error occurs in line #2. The blank fields show processes where the error occured:
  <img src="https://i.stack.imgur.com/CnOdi.png" alt="Screenshot"></p>
  
  <p>Is there any way to get around this error message?</p>