2

I develop C# applications using VS 2010 Ultimate. Usually, those applications run for long time, without user interaction and, of course, they usually have bugs inside.

Unfortunately, often the application crashes randomly and you just can't reproduce the error. Also sometimes I only have the message "The application has stopped working" with no more informations.

I can install Visual Studio on the machine of the customer, but I can't let him run VS and compile/start the source code in debug mode! What I need is to start VS after the application was started and crashed. It seems to be possible to do this, in fact when an exception happens at runtime, Windows ask you "do you want to debug with VS?", but if I answer YES, then VS starts but simply I can't see the source code (it is on the pc as well), thus I can't inspect the row of code that is causing the exception. VS just tells me "source code not available". Actually, I can't imagine how Windows could start VS and know where the source code of the crashed application is!

Does anyone knows how does this debugging scenario is intended to work, and how to configure it??

Thanks a lot, Simone

3 Answers3

1

Windbg debugging tool solves the purpose.

Take dump of the process state and start analyzing with windbg. It gives you the exception information

Rockstart
  • 2,337
  • 5
  • 30
  • 59
  • Hi Rockstart, thanks for your suggestio: just don't know how to dump the process! – user1378544 May 08 '12 at 19:32
  • If you are using WinXP , use ProcessExplorer to create dumps. If win7 , you can right click on process in task manager window and create dump. Please see here [John Robbins's Blog](http://www.wintellect.com/cs/blogs/jrobbins/archive/2010/06/17/how-to-capture-a-minidump-let-me-count-the-ways.aspx) – Rockstart May 09 '12 at 04:47
1

To debug from an already-running Visual Studio instance, select the "Debug" menu item, then "Attach to Process..."

Attach to Process

Next, select the executable from the list, press "Attach" (or double-click), and you are now debugging the application. When you select "Yes" and Windows says that source code is not available, this most likely means that the PDB wasn't able to be loaded, so make sure that you have loaded the symbols for the module by examining it in the "Modules" window pane.

Lander
  • 3,369
  • 2
  • 37
  • 53
  • I can't connect to the process, because when the exception happen Visual Studio is started and automatically attached to the process that has crashed, but this is ok. Anyway, I thankyou Lander, because I do not know about the Modules panel, and also I found under the message "Source not available" a link that said "Find source": just clicked and located the source file and it worked! Thankyou a lot!! – user1378544 May 08 '12 at 19:26
  • Yes, I believe you can only have one instance of the debugger attached at once. Attach before the exception is thrown, and if you choose to break the process you can add breakpoints and whatever else you please. – Lander May 09 '12 at 20:42
0

If you want to catch errors while running compiled program, you should use some sort of logging mechanism. These days you don't have to write it on your own, there's a great opensource logging engine designed for .NET applications, it's called NLog. It's capable of saving logs into files, emails, console or database, pretty much all you can want :).

Hope this helps :)

Community
  • 1
  • 1
  • Thankyou Ernestas, I know about NLog, but if I don't know where the exception happen I don't know what to log, and simply I can't add log line for every source line, of course! In addition, the software is multithreading, and this make very difficult to interpret the log output because it is sequential... – user1378544 May 08 '12 at 19:31