exception 0xC0000008: An invalid handle was specified. thrown during file creation when debugging application


  • Hello

    I have been working on a project in C# and last night out of the blue started hitting a SEHException when trying to create a file using System.IO.File.OpenWrite, the exact same code had been working for several weeks before hand and had not changed. after trying everything i could think of, to no avail, i decided to try in C++ and it turns out i can no longer perform any kind of file creation operation with the visual studio debugger attached.

    My simple C++ test program is:

    #include "windows.h"
    int main(int argc, char const * const * argv)
      // this throws an exception when debugging but works fine when running without the debugger
      HANDLE h = CreateFile(TEXT("test.test"), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
        DWORD dummy;
        char buffer[] = "Test text that's only written if CreateFile succeeds";
        WriteFile(h, buffer, sizeof(buffer) - 1, &dummy, 0);
    when running with the debugger attached the program throws an invalid handle exception when opening the file. If i detach the debugger with the program broken on the create file line or if i run the program without the debugger attached it executes correctly creating the file and writing the text to it.

    i've tried the obvious things such as restarting my computer and am starting to think the best option would be to reinstall visual studio as i can no longer debug any useful application. Can anyone advise me on any steps to analyze or fix this issue? I've tried looking the programs io events using process monitor but there's no obvious differences between the working version without the debugger attached, and the version which throws the exception with the debugger (except for the write event)

    My machine is running windows 7 x64 and I'm using visual C++ 2010 express edition / visual C# 2010 express edition the problem occurs both in debug and release builds, I'm building for the x86 platform.

    Thanks for your time

       -Peter Nicholls

    • Edited by ChaosBlue Tuesday, August 2, 2011 8:56 PM tried to sort out code formatting
    Tuesday, August 2, 2011 8:52 PM


All replies

  • I started getting this exact same problem last night as well!

    see here

    My website: My blog:
    Tuesday, August 2, 2011 9:03 PM
  • Thanks for the links chris128 you have saved me the pain of reinstalling visual studio although I'm starting to think that i'll have to reformat my computer; i'll keep watching the forums for a little longer in the hopes some kind of solution arises
    Tuesday, August 2, 2011 9:10 PM
  • I was considering doing the same thing (reformatting) but if this is affecting a lot of other people at the exact same that it started affecting me (see this thread: then I don't know if it is just a random glitch that reformatting will fix... I know that might not look like the same issue as yours and mine, but I think it is just another symptom of the same problem because I now have that same issue described there whenever I launch any winforms apps, and again that only started yesterday afternoon.

    I'm going to file it as a bug on the MS Connect site and see if they have any answers.

    My website: My blog:
    Tuesday, August 2, 2011 9:16 PM
  • Here's the Connect bug log: . You might want to click the "I can reproduce this error too" thing so that it gets more attention :)
    My website: My blog:
    Tuesday, August 2, 2011 9:29 PM
  • sure will do thanks
    Tuesday, August 2, 2011 9:32 PM
  • To solve the problem uninstall Trusteer Rapport as per this was the issue for me
    • Marked as answer by ChaosBlue Tuesday, August 2, 2011 9:49 PM
    Tuesday, August 2, 2011 9:49 PM
  • Thanks! :) I should have realised as I did a Process Monitor trace of my app starting up and saw tons of entries for Rapport but just ignored it because I assumed that was normal... Once VS SP1 has finished uninstalling (yeah I thought I'd give that a go) I'll try uninstalling Rapport and hopefully that will fix it, thanks again

    My website: My blog:
    Tuesday, August 2, 2011 10:07 PM
  • Yep, uninstalled Rapport and it all works perfectly again :)
    My website: My blog:
    Tuesday, August 2, 2011 10:45 PM
  • Removing Rapport fixed the problem for me too. Thanks a lot guys. Rapport is forever dead for me. It caused me two days of tracing ghosts and waisted time. It is so simple for any software to anounce that it is updating itself, but not for Rapport.

    Thanks again, guys!

    Wednesday, August 3, 2011 4:47 PM

    Thank you all for the much appreciated input    .

    First, we would like to express our sincere apologies for any inconvenience caused by this conflict. The problem started following a regular security update which Rapport performs in order to keep your system's security at it's most secure level against today's rapidly changing malware threats.

    Secondly, we are glad to inform you that the conflict with Visual Studio has been resolved in the latest Rapport version.

    You can download this version from the following link:

    Should the problem persist, or if you encounter any other problem, please contact us by submitting the following form:

    Once again, please accept our sincere apologies for the inconvenience.


    Best regards,

    Trusteer Support



    Thursday, August 4, 2011 11:14 PM