System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception
<p>I have  code written in C# on a Windows7 and VS2010, 32 bit using .Net 3.5 and it is runing without any problem, now I converted it to 64 bit using .Net 4.0 but I got an error when my code call CloseHandle.</p>

<p>ERROR - CloseHandle<br>
System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.</p>

<pre><code>unsafe
{
    fixed (byte* p = readBuffer)
    {
         IntPtr intPtr = (IntPtr)p;
         this.ReadFile(ref sourceFile, (ulong)buffer_size, intPtr, ref nNumBytesRead);

         if (intPtr != IntPtr.Zero)
         {
             try
             {
                 FunctionSqudf.CloseHandle(intPtr);
             }
             catch (Exception ex)
             {
                  Hardware.LogHardware.Error("CloseHandle", ex);
             }
         }
      }
  }


    [SecuritySafeCritical]
    [DllImport("kernel32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    internal static extern bool CloseHandle(IntPtr hObject);
</code></pre>

<p>Any help is appreciated.</p>
