I built a console application that allows users to drag and drop files on to it and it will process it. However, it crashes while it’s processing the file and I don’t know what’s going on.
How can I debug this? The console closes too fast for me to see what the issue was, and I can’t reproduce the error when I call it through command-line and specify some args there.
The procedure is as follows
- In windows explorer, I drag my input file (an image) over an exe
- The exe would then read the image and do something with it
- I then save the image in a new file
The crash occurs during the saving, but I am not too interested in where the issue is, but the fact that I can’t come up with a way to actually debug this properly.
If your app is started automatically by some other program (like explorer) – configure Launch debugger on process start.
Another simple way (when tweaking registry is not an option) is to add Debugger.Break in your code to have chance to attache debugger. Or even Thread.Sleep(10000) to give you chance to catch it.
There is nothing very specific about drag-n-drop (unlike focus issues that often require remote debugging).
Either start application form VS with correct parameter or attach to running appliction. You may want to turn on “Debug->Exception->break when thrown” for CLR exceptions (may need to disable “Tools->Options->Debug->My code only”).
Watch output window while attached to the process for any suspicious traces.
If VS is getting in a way you can use WinDbg the same way… But try VS route first before.