Showing posts with label Debugging. Show all posts
Showing posts with label Debugging. Show all posts

Debugging Visual Studio Generated Strongly Typed DataSet Code

Tuesday, March 4, 2008

Sometimes you may face a situation when you need to debug Visual Studio generated code. For example, when you create strongly typed DataSets, Visual Studio generates corresponding code.

If you put a break point in such code, to your surprise the debugger will not fire it. This happens because the v2.0 CLR debugging services has a feature called Just-My-Code (JMC for short) debugging. By default this is enabled in Visual Studio. Hence, all code (methods) marked with System.Diagnostics.DebuggerNonUserCodeAttribute will be ignored by the debugger and no break points set in such code will be fired.

This is a pretty nice feature to avoid needless stepping in 3rd party code and Visual Studio generated code as well. However, as mentioned above, sometimes we need exactly the opposite, i.e. to be able to debug the Visual Studio generated code.

You can disabled JMC in Visual Studio options as shown on the screen shot below. Simply, clear the Enable Just My Code (Managed only) check box.

Mike Stall has a pretty nice article about JMC in his blog, which you can find here:

Drag-and-Drop Not working When Debugging in Visual Studio Under Windows Vista

Tuesday, October 30, 2007

There are many programmers out there working on real-world applications who have not programmed drag-and-drop functionality. However, sooner or later, you will need this nice feature of Windows (and GUI in general).

Adding drag-and-drop support to your application is not difficult in C#/.NET. However, when it comes to debugging drag-and-drop under Windows Vista that's when trouble begins. If drag-and-drop does work fine when you run the application from Explorer but does not when you run from Visual Studio 2005 don't be surprised. We will demystify this quickly. However, I must admit that it took me about and hour to figure out what was wrong.

As you are well aware, under Windows Vista, we usually work from a low privilege account. However, because this causes some problems when working in Visual Studio, most of the programmers run Visual Studio with Administrator privileges. It turns out that Windows Vista does not allow drag-and-drop operation if you are dragging from a lower privilege application to one with administrator privileges. So now it's easy to explain the strange behaviour.

When you start the application in a debug mode, Visual Studio has administrator privileges and if you try to drag-and-drop say from your desktop (which most likely has low privileges) the operation fails. Visual Studio would not even fire the drag-and-drop events.

So, what do we do when we need to run Visual Studio under administrator privileges and yet be able to debug drag-and-drop? Well, now when we have demystified the strange behaviour, we can solve this problem. This is how I solved this. I use Total Commander as my File Manager. So I run both Total Commander and Visual Studio with administrator privileges and drag-and-drop debugging works just fine.

Happy programming!

More cool posts coming soon.