Home How to get WPF application to break in code?
Reply: 1

How to get WPF application to break in code?

LL201 Published in 2018-01-12 16:47:33Z

When debugging in .NET, I really enjoy being able to step directly into my code when an error is triggered at a certain location. When programming a WPF application, however, I can't seem to access this feature.

Consider this simple program:

sub breakMe()
   dim badObject as Object = nothing
 end sub

sub getObjectString(whatObj as object)
 end sub

If this were a winforms project, the debugger would break right on the "whatObj.toString" line and I could step into the call stack there and jump around into any prior procedures and check object values throughout. With WPF, however, there is an unhandled exception triggered that makes this impossible.

I've read many, many examples of ways that you can add handlers to WPF which allow you to custom handle exceptions so that you can view the relevant stack trace. While helpful, this is still not nearly as good as being actually able to step into the code exactly where it breaks and view object values.

You could add try blocks to achieve the desired result, but that would obviously be impractical to do throughout the project, and it seems like there should be an easy way to do this. Perhaps by forcing the debugger to simply bypass the handlers for the WPF graphical components?

Dean Kuga
Dean Kuga Reply to 2018-01-12 17:31:36Z

Exception is most likely thrown by some error in your XAML, not in your C# code.

To learn how to get more information on errors in XAML read this article:

How to: Display WPF Trace Information

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.299075 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO