Debugging Windows Store application on local machine - c#

I am trying to debug Windows 8 C# Store application with Local Machine debugger. So, I added some incorrect line to MainPage constructor, after InitializeComponent call. I tried the code that causes DivideByZero or NullReferenceException - with the same results.
So, I execute "Start Debugging", and debugger breaks here:
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
#endif
Stack information is not available, it is impossible to detect where is an error (only first-chance exception message in the Output window gives a hint).
I tried to define DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION in the project preprocessor symbols. This time I got the following strange message: "A debugger is attached to YourProgram.exe but not configured to debug this unhandled exception".
Only when specific exception type is checked in the "Exceptions" dialog, and DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION is defined, I managed to break on the line which caused the error.
So, what is the right way to break on the offending line, like is was in traditional desktop applications debugging? If possible, without modifying Exceptions list. And what is exactly the purpose of DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION constant?

It looks like a xaml parsing exception. Have you be able to look at the exception message and see where the error is?
Here is some sample screenshot:

Well when you start Visual Studio you must click on debug and then Options and Settings and then General in Debugging and click on Enable Just My Code.

It can be helpful to enable "Common Language Runtime Exceptions" in "Debug/Windows/Exception Settings" before debugging.
Visual studio will now break on the actual error.

Related

The application is in break mode -- cannot properly debug

I have a wpf application that I am creating and whenever I try to debug my code and reach an exception I am given the message "The application is in break mode". I am able to see the exception thrown but I am not given the line that the error was thrown.
I did look through some threads and the solution most people gave was to go to Tools > Options > Debugging > General > then to uncheck Enable Just My Code. I did this and I get a similar error but instead the error message is "AsyncMethodBuilder.cs not found". I then looked for a solution to that error and was told to check Enable Just My Code.
Is there a solution to "The application is in break mode" that does not consist of unchecking Enable Just My Code?
I decided to rebuild the entire project and that seemed to fix my issue.

VisualStudio 2017 - always show exceptions

I have a Visual Studio App (Windows.Forms) that build a release .exe-App. If I run this exe an exception occurs, I only can see it in the windows log, nothing more happens.
But I would like to see the JIT Exception Window. Can I activate this somehow in VS?
Im asking for a general "If any exception at runtime - show the JIT Debugger"-switch. Is something like this available?
Did it now like here shown.
http://www.csharp-examples.net/catching-unhandled-exceptions/
Instead of logging made an MessageBox with the Exception Message und Application.Exit(). Works exactly as i like it to have.

Visual Studio 2015 debugger stops for a handled exception of a DebuggerHidden function

I want the debugger to stop when:
A handled or unhandled exception occurs.
An unhandled exception occur in a function that has a DebuggerStepThrough or DebuggerHidden attibute. Debugger should stop where this function is being called.
There is no problem so far, I could able to make Visual Studio 2015 work like that. However when an handled exception occurs inside a function that has a DebuggerStepThrough or DebuggerHidden attibute, the debugger stops where this function is being called.
I couldn't find a way to fix this. I don't remember this behavior on Visual Studio 2010 or 2013. I've searched about it, and did not find anybody asking about the same issue.
Edit:
I have tried DebuggerNonUserCode, result is the same. It says "Exception thrown". No it does not!
My settings:
You could use the DebuggerNonUserCode Attribute instead of the DebuggerStepThrough or DebuggerHidden attribute in VS2015 since there are a few small differences between them:
https://blogs.msdn.microsoft.com/visualstudioalm/2016/02/12/using-the-debuggernonusercode-attribute-in-visual-studio-2015/
Update:
I get the same issue as yours using the VS2015. I found that it would be related to on debugging option, please enable the option "Use Managed Compatibility Mode" under TOOLS->Options->Debugging. Debug it again.
The MSDN article Using the DebuggerNonUserCode Attribute in Visual Studio 2015 explains what the DebuggerNonUserCode does and why it doesn't ignore exceptions.
This is caused by a performance improvement in VS 2015
when Just My Code is enabled, the debugger no longer gets notified of exceptions that are thrown and handled outside of “your code”.
This leads to a big performance improvement because:
The debugging performance improved because when Just My Code is enabled, the debugger no longer gets notified of exceptions that are thrown and handled outside of “your code”.
This behaviour can be switched off through a registry key introduced with Update 2:
To enable this, run the following command from your command line that will tweak the registry for you:
reg add HKCU\Software\Microsoft\VisualStudio\14.0_Config\Debugger\Engine /v AlwaysEnableExceptionCallbacksOutsideMyCode /t REG_DWORD /d 1
You'll have to experiment and see what is more important, ignoring exceptions or better debugger performance.

Visual Studio error: "The debugger cannot unwind to this frame." on any exceptions

I used to be able to edit and continue when an exception occurred in my Visual Studio 2015 C# (WPF if relevant) projects. I often get simple things like null reference exceptions, and I could just quickly fix the issue and continue.
However, recently I've been constantly getting the following warning message:
"The debugger cannot unwind to this frame."
It notes that unwinding is nor possible in the following:
Debugging was started via Just-In-Time debugging. - This isn't the case, I'm debugging by running the "Start debugging" from Visual Studio.
An unwind is in progress - Not that I'm aware of, unless for some reason it's always in progress!
A System.StackOverflowException or System.Threading.TreadAbortException - This happens on all exceptions, including simple ones like Null Reference
My googling comes up with a few articles saying they've implemented this feature in 2006, other than that, only about 3 results come back!
It seems to be project specific. In a clean new project:
Object o = null;
String s = o.ToString();
Throws an exception, and lets me edit and continue the line before. In my existing project I cannot unwind and it throws up the dialog.
Edit: Tried it with a different computer and Visual Studio install and still have the issue.
It seems to be an issue with Caliburn Micro.
If I have a button on my user interface linked to an event in the code behind with the above code, I can rewind and debug. However, If I use cal.message.attach and put the code in the referenced ViewModel's method, then I cannot unwind. But I'm not sure.
You can try and test these solutions one by one.
Unwinding exceptions is unreliable in optimized code. Debug | Options - Check 'Enable Just My Code'
Debug | Options - Check 'Use Managed Compatibility Mode'
Debug | Options - Uncheck 'Enable property evaluation and other implicit function calls'. If that doesn't work, also:
Debug | Options - Check 'Use the legacy C# and VB expression evaluators'
Debug | Windows | Exception Settings - Expand the 'Common Language Runtime Exceptions' dropdown. Make sure your exception is checked.

C# SystemNullReferenceException in WindowsForms

I'm having the following error when closing a form in an application
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
***** Exception Text *******
System.NullReferenceException: Object reference not set to an instance of an object.
at Infragistics.Win.UltraWinGrid.UltraCombo.get_Text()
at Infragistics.Win.UltraWinGrid.UltraCombo.OnEnter(EventArgs e)
at System.Windows.Forms.Control.NotifyEnter()
at System.Windows.Forms.ContainerControl.UpdateFocusedControl()
I'm almost sure that this has something to do with the fact that I'm using multithreading to populate some data, but my problem is that I'm not able to determine the place in which the call to the method is being made.
A .Net framework appears and I can only click continue or close, but what I really wanted was an application crash to determine what is causing the error. This is even more complicated because it only happens with compiled code. Do you know any profiler or technic to catch the error?
Can I attach the debugger to my exe to capture the method throwing the error?
UPDATE:
What I really want is to enable JIT debugging and have access to the stacktrace tho determine the cause of the error, I've done that by adding the
<system.windows.forms jitDebugging="true" />
to the config file as described in MSDN to my config file, but now I'm not getting any error at all.
Bottom like, can I do anything else for the framework give additional details about the error?
You can set Visual Studio up to break on specific types of exceptions. There is an Exceptions dialog under the Debug menu. Just check the exception you wish to break on and run the code with the Visual Studio Debugger attached.

Categories

Resources