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

    Question

  • 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);
      if(INVALID_HANDLE_VALUE != h)
      {
        DWORD dummy;
        char buffer[] = "Test text that's only written if CreateFile succeeds";
        WriteFile(h, buffer, sizeof(buffer) - 1, &dummy, 0);
        CloseHandle(h);
      }
    }
    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

Answers

All replies

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

    see here http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/2c131bbb-3b6c-4782-b25d-1854009d70e4


    My website: www.cjwdev.co.uk My blog: cjwdev.wordpress.com
    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: http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/d92580e5-9f58-44eb-bb85-fe9f7b9173f4) 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: www.cjwdev.co.uk My blog: cjwdev.wordpress.com
    Tuesday, August 2, 2011 9:16 PM
  • Here's the Connect bug log: https://connect.microsoft.com/VisualStudio/feedback/details/682722/an-invalid-handle-was-specified-when-launching-any-net-4-0-apps-in-debugger . You might want to click the "I can reproduce this error too" thing so that it gets more attention :)
    My website: www.cjwdev.co.uk My blog: cjwdev.wordpress.com
    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 http://forums.asp.net/t/1704958.aspx/7/10?Re+SEHException+thrown+when+I+run+the+application 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: www.cjwdev.co.uk My blog: cjwdev.wordpress.com
    Tuesday, August 2, 2011 10:07 PM
  • Yep, uninstalled Rapport and it all works perfectly again :)
    My website: www.cjwdev.co.uk My blog: cjwdev.wordpress.com
    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: http://download.trusteer.com/Gcur4Wtnu/RapportSetup.exe

    Should the problem persist, or if you encounter any other problem, please contact us by submitting the following form:http://www.trusteer.com/support/submit-ticket

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

     

    Best regards,

    Trusteer Support


     

     

    Thursday, August 4, 2011 11:14 PM