pythonwpfvisual-studioptvs

Visual Studio Python WPF debugging


So I spend almost all of my programming time on Linux, but recently, for a project, I had to try out PTVS and WPF. As it is a very good framework, I would like to learn it further, but the issue in question is a huge disadvantage when compared to running python programs on Linux. So say I have a little WPF project on IronPython2.7, with some buttons and some functions handling those buttons' click events. The problem is that not every exception/error present in that code is shown in debugger: sometimes it just says "the process exited with code 0x01". That, for example, happens if I try to access an array element outside of array bounds. The question is: is there a way to fix this and be able to see all the errors and exceptions while debugging a WPF program?


Solution

  • By default, IronPython projects in Visual Studio run using the managed debugger. This makes it really easy to debug mixed Python/.NET code, however, you don't get quite as nice an experience when you only have Python code.

    To change this, right-click your project in Solution Explorer and select Properties. On the Debug tab, there's a dropdown for the launcher - you can see a screenshot here.

    It's probably got IronPython (.NET) launcher selected, but changing it to Standard Python launcher should give you better pure-Python debugging. The downside is that you won't be able to step into .NET code anymore, and it's a little bit more invasive. In general though, the improvements are worth it if you are not using IronPython to extend a .NET application.