0

I am using visual studio 2008 (32 bit. My machine is 64 bit). I've build an windows forms EXE application. Now I want to attach the process in visual studio so that when I run the EXE from Debug/Release folder of my project it should hit the breakpoints that I've set in my code which is currently opened in visual studio 2008.

I can see there is a process called MyApplicationName.vshost.exe but the attach button is grayed out.

The reason I wnat to debug the EXE is, I want to debug the EXE at run time. I am getting an exception when I run the EXE from Debug/Release folder but when I run through the code I didn't get any exception

Please let me know which process should I attache in VS2008 so that when I run my EXE from Debug/Release folder of my project it should hit the breakpoints that I've set in my code which is currently opened in visual studio 2008.

Swad
  • 41
  • 1
  • 8
  • Why don't you directly run the application from vs? But otherwise you should still be able to attach vs to the normal process, there shouldn't be a lot of them if you built a normal small application. Are you sure that you executed the normal exe file from the bin/debug folder? – MetaColon Mar 18 '17 at 16:30
  • 1
    Agreeing with @MetaColon, this doesn't seem like a normal workflow. If it helps, you can compile a [Debugger.Break()](https://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break(v=vs.110).aspx) call into your application (maybe guarded with a command-line switch or conditional compilation). When that statement runs, Windows will ask if you want to attach a debugger and you can pick a running instance of Visual Studio or start a new one. – Tom Blodget Mar 18 '17 at 16:34
  • @MetaColon the reason is I want to debug the EXE run time. I am getting an exception when I run the EXE from Debug/Release folder but when I run through the code I didn't get any exception. – Swad Mar 18 '17 at 16:34
  • @TomBlodget added "Debugger.Break()" to my code. I am getting error as "unable to start debugging". Remote debugging monitor has been closed on remote machine – Swad Mar 18 '17 at 16:38
  • [Heisenbugs](https://en.wikipedia.org/wiki/Heisenbug) are a challenge. Wikipedia has a small section on resolution. – Tom Blodget Mar 18 '17 at 16:40
  • This [answer](http://stackoverflow.com/a/2059254/2226988) might help. Also, please [edit] your question to describe the original problem. – Tom Blodget Mar 18 '17 at 16:45
  • @TomBlodget can you please comment on following issue: "I can see there is a process called MyApplicationName.vshost.exe but the attach button is grayed out." – Swad Mar 18 '17 at 16:52
  • This might help: [Hosting Process (vshost.exe)](https://msdn.microsoft.com/en-us/library/ms185331.aspx). Are you not able to set a breakpoint in Visual Studio, debug the application and break on that point? – InteXX Mar 18 '17 at 18:39
  • Are you debugging the .exe running on a remote machine? Or is it running locally? – Chris Dunaway Mar 20 '17 at 15:16
  • @Swad, would you please share the latest information about this issue? – Jack Zhai Mar 29 '17 at 03:07
  • @JackZhai-MSFT i used Debugger.Break() in my code and when encountered break I choose "Current Visual Studio instance" – Swad Apr 01 '17 at 07:05
  • @Swad, As you said that you get the exception if you run .exe directly, but not in VS IDE, I suggest you use the JIT debugging which would help you captured/debug the exception outside the VS. https://msdn.microsoft.com/en-us/library/5hs4b7a6(v=vs.90).aspx – Jack Zhai Apr 04 '17 at 05:49

1 Answers1

0

If you have the source code, I also suggest you debug your app directly, you could use the Exception throw under Debug->Exceptions window which could help you throw the Exception messages.

For host process, if possible, you could disable it under project property:

enter image description here

If you have to use the attach to process, please run VS as the admin, and then attach to your process directly:

enter image description here

Jack Zhai
  • 6,230
  • 1
  • 12
  • 20
  • @Swad, is it helpful for you? If it is the solution, please mark it. If not, share the latest information for it:) – Jack Zhai Apr 03 '17 at 02:14