Visual Studio is a great IDE for debugging any application, whether it’s a web, mobile, or a desktop application. It uses the same debugger that comes with the IDE for all three, and is very easy to follow. In this tutorial, we will learn how to debug a mobile application using Visual studio.
This article is an excerpt from the book, Mobile DevOps, written by Rohin Tak and Jhalak Modi.
The output window in Visual Studio is a window where you can see the output of what’s happening. To view the output window in Visual Studio, follow these steps:
The Console class can be used to print some useful information, such as logs, to the output window to get an idea of what steps are being executed. This can help if a method is failing after certain steps, as that will be printed in the output window.
To achieve this, C# has the Console class, which is a static class. This class has methods such as Write() and WriteLine() to write anything to the output window. The Write() method writes anything to the output window, and the WriteLine() method writes the same way with a new line at the end:
As described earlier, breakpoints are a great way to dig deep into the code without much hassle. They can help check variables and their values, and the flow at a point or line in the code.
Using breakpoints is very simple:
You can also set a conditional breakpoint in the code, which is basically telling Visual Studio to pause the flow only when a certain condition is met:
So, the breakpoint will only be hit when this condition is met; otherwise, it’ll not be hit.
When a breakpoint has been reached, the debug tools enable you to get control over the program’s execution flow. You’ll see some buttons in the toolbar, allowing you to run and step through the code:
You can hover over these buttons to see their respective names:
A watch is a very useful function in debugging; it allows us to see the values, types, and other details related to variables, and evaluate them in a better way than hovering over the variables.
There are two types of watch tools available in Visual Studio:
QuickWatch is similar to watch, but as the name suggests, it allows us to evaluate the values at the time. Follow these steps to use QuickWatch in Visual Studio:
Adding a watch is similar to QuickWatch, but it is more useful when you have multiple variables to analyze, and looking at each variable’s value can take a lot of time.
Follow these steps to add a watch on variables:
To summarize, we learned how to debug a Xamarin application using Visual Studio. If you found this post useful, do check out the book Mobile DevOps, to continuously improve your mobile application development process.
I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…
Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…
Once we learn how to deploy an Ubuntu server, how to manage users, and how…
Key-takeaways: Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…
While developing a web application, or setting dynamic pages and meta tags we need to deal with…
Software architecture is one of the most discussed topics in the software industry today, and…