Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable WPF exception wrapping for debugging

Is there an way to disable WPF's very annoying exception wrapping when debugging?

An example would be a window that owns a text box, the text box is bound to a property, the getter on that property throws an exception that can't be handled by the presentation framework (throw new StackOverflowException() for example).

What I'm should be seeing is

        get
        {
            throw new StackOverflowException(); // < Exception happened here
        }

Instead what I'm seeing is...

    No Source Available
    Call Stack Location:
    PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.RawValue(int k) + 0x64 bytes  

Because of WPF's exception wrapping this exception is also sometimes caught and dispatched then is either rethrown or hidden deep within MS.Internals and impossible to return to the actual site of exception. This results in us seeing a gigantic callstack of PresentationFramework.dll, PresentationCore.dll, and WindowsBase.dll but NO user code except for App.Main().

This occurs during binding, events called during creation, and other completely random situations without rhyme or reason (exception during button click sometimes does this to me). Now yes I can look at stack trace inside of the exception but that stack trace is also pretty much meaningless because I cannot return to that frame to see what the variables are that at the time of throw.

like image 699
NtscCobalt Avatar asked Nov 01 '11 18:11

NtscCobalt


1 Answers

Generally when debugging I'd use the debug -> exceptions and select thrown for Common Language Runtime Exceptions. This will then halt at the point that the exception is thrown.

Visual Studio 2010 Exceptions dialog with common language runtime exceptions ticked

like image 140
Richard Harrison Avatar answered Oct 28 '22 00:10

Richard Harrison