title: C# Only part of a ReadProcessMemory or WriteProcessMemory request was completed during Process.Kill()
body: <p>I have been researching this issue pretty extensively and cannot seem to find an answer.</p>
  
  <p>I know that the <code>Only part of a ReadProcessMemory or WriteProcessMemory request was completed</code> exception is thrown when a 32-bit process tries to access a 64-bit process and the same for a 64-bit modifying a 32-bit process. </p>
  
  <p>The solution to that issue is to change the Platform Target to 'Any CPU'. I have tried this and unfortunately this does not solve my issue. </p>
  
  <p>The next block of code is what keeps throwing the exception. The program that runs this code is used to open up applications on remote computers and keeps a list of all the processes that the program itself opened so that I don't have to loop through all the processes.  </p>
  
  <pre><code>Process processToRemove = null;
  lock (_runningProcesses)
  {
      foreach (Process p in _runningProcesses)
      {
          foreach (ProcessModule module in p.Modules)
          {
              string[] strs = text.Split('\\');
  
              if (module.ModuleName.Equals(strs[strs.Length - 1]))
              {
                  processToRemove = p;
                  break;
              }
          }
          if (processToRemove != null)
          {
              break;
          }
      }
      if (processToRemove != null)
      {
          processToRemove.Kill();
          _runningProcesses.Remove(processToRemove);
      }
  }
  </code></pre>
  
  <p>These processes can and most likely will be 32-bit and 64-bit, mixed together.</p>
  
  <p>Is there anything I am doing that I shouldn't be doing, or is there just a better way to do all of this?</p>