title: PInvokeStackImbalance was detected on WriteFile kernel32.dll
body: <p>After i migrated from Framework 2 to framework 4, i get an error when i run the WriteFile function.</p>
  
  <pre><code>[DllImport("kernel32.dll")]
          public static extern bool WriteFile(SafeHandle hFile,
              byte[] lpBuffer, 
              uint nNumberOfBytesToWrite, 
              out uint lpNumberOfBytesWritten, 
             long lpOverlapped);
  </code></pre>
  
  <p>Solution:</p>
  
  <pre><code> [DllImport("kernel32.dll")]
          public static extern bool WriteFile(SafeHandle hFile, 
              byte[] lpBuffer, 
              uint nNumberOfBytesToWrite, 
              out uint lpNumberOfBytesWritten, 
             **Int32** lpOverlapped);
  </code></pre>
  
  <p>The lpOverlapped parameter should be a int32, which is an unsigned long in
  umanaged C++.</p>
  
  <p>Original Error:</p>
  
  <p>PInvokeStackImbalance was detected
  Message: A call to PInvoke function '' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.</p>