>> Hi.
Sayede Hashimi here.
We're going to talk today about how you can improve
your debugging experience and Visual Studio for Mac.
So you've got a good amount of content to cover.
So let's just get right into it.
So I'm going to start off with some features which we've recently
enabled for.NET Core projects and Visual Studio for Mac.
You can see here I've got an ASP.NET
Core solution loaded here consists of four different projects.
I haven't set any breakpoints yet.
Let me go ahead and start debugging this application,
and then after it gets started,
we'll set some breakpoints.
So now we can see that the website
has come up and it also launched
a browser for a API project
that I have as a part of this solution.
So first what I want to do is I want to go and set a break point,
and then we'll start exploring
the different features that we have.
So I've set a break-point here inside the crate
from template function here,
and this is a method that I know
is going to get hit as the default page loads up,
so let me go ahead and refresh this page.
So now we can see that the break-point has been hit.
So now we're online 84.
So let's explore some features
which have recently been added here.
So one of them is called run the cursor.
So let's imagine you've got your break-point here,
and you're not really
interested in stepping through this double for each loop.
But what you want to do is you want to inspect
the result object after that's done.
So what you can do is you can right-click in your code,
and then say run the cursor.
So what that will do is it will execute the code that follows and
then when the control reaches that particular part of your code,
the debugger will then pause your application and then you
can use the debugger features as you normally would.
So now there's there's also
a very similar but different functionality
that we have as well that we've recently added.
So let's say you've been debugging this application,
and you're currently at line 97.
But what you want to do is you really want to go back to line
84 and then step into create from text.
So what you can do is you can right-click
and then say set next statement.
So I just invoke that,
and now we can see the debugger is now online 84.
This might seem like it's similar to run the cursor,
but it's very different.
Running the cursor will continue execution of your application,
and then when it reaches the desired line,
it will pause, set
next statement literally sets the next statement wherever
you've indicated and there's no code that's being
executed in between those two points.
So now we can see I can then step into the crate from text file,
and then do whatever debugger operation
that I was interested in doing there.
So now let's say you've been debugging your app,
and you then explored various different parts of the code,
and now you want to go back to where the debugger has stopped.
So you can easily do that with the Run menu here.
So on run, you can go down to show current execution line.
Let me invoke that, and we can see that
it's brought us back to the create from texts method here,
and that's where we were paused previously.
So now let's move on to some more general debugger features
which have been supported in the product for a long time.
So I'm going to open a different file
here and set a new break-point.
So this is the OnGetMethod.
This is the part of the website that we recently saw.
So let me continue the debugger,
and then I'll go back to the browser and do a refresh.
So that way we can hit that,
let's ignore this error for now.
That was probably related to my set next statement.
Let me turn off this break point and then continue.
We can see that we're back to
the break-point that we've just set up here.
First to hover over this template packs and expand it,
we can see the value of that.
So I've expanded that list and it's like 235 items here,
and you can see that the default display here is not
really telling me much about
the template pack which is being displayed here.
What I would like to do is try to
modify the code to where I can have
a more descriptive string here instead
of just the standard toString.
Let me go ahead and I'm going to stop debugging here.
The object I want to modify is this template pack.
So I'll say go to declaration,
and the way that you can do this,
you can add an attribute to your code,
and that system diagnostics debugger display,
and this is actually I'm using a very basic way here.
So all I'm saying is to
display the value for the package property,
we can see that property is defined down here.
That's the name of the NuGet package that
the template is contained in.
So let me go ahead and save that,
and then we'll start
debugging one more time and wait for that break-point to get hit.
Now we can see the break point has been hit.
Let's go ahead and hover over template packs
one more time and then inspect it.
So instead of getting the same string repeated 235 times,
now I can go in and I can actually go through
and find the item that I want to inspect here.
So let's take a look at Match Christiansen.
He's got some templates that he's created for.NET New,
and then we can go to and then inspect
those objects as well if we needed to.
So I showed you on hover that the debugger display attribute,
then will show up for on hover,
but we can also get that power to gone to locals and watch window.
So let me go into the locals window here,
and then under this I must find a template packs.
I'll drill into template packs.
So we can see those same strings do
appear in the locals and
that would also appear in the watch window as well.
This is not limited to Visual Studio for Mac,
Visual Studio on Windows has had
this similar support for as long as I can remember as well,
and I believe that the Visual Studio Team has recently put
out a blog about
more information for a debugger display attribute.
So I'm going to go ahead and stop debugging here,
and then, no, actually I'm going to let it continue debugging.
What I want to do now is let's say in your code,
let's say you're running into a situation
where there's an exception being thrown somewhere,
but you're not sure where it's at,
and you're not really sure where to set the break-points.
So what you can do is go into run a new break point,
and then we can say,
you want to stop let's say when any exception has been thrown.
So I went into the crater break-point,
I selected when an exception is thrown,
then I'll pick a system dot exception and then
make sure that includes sub classes is also checked.
So I'll say go ahead and create that break-point.
I'm going to go back to the website
and perform an operation that I know
that is likely to throw an exception.
You can go ahead and continue.
I'm going to drill into a template pack,
and then I'm going to change the URL
to something that doesn't exist.
So I just made a little change there.
So now this should raise an exception in the code, there we go.
So now I've got a null reference exception
that's being thrown online five.
What we want to do now is we can either
do on hover here to inspect this,
and in this case it looks like the model value is fine,
but the template pack,
it looks like it's probably null.
But one thing we can leverage here if you
didn't want to use the on hover,
you can always go into the expression evaluator,
and I got to that with the run menu.
So I can say model,
and I can enter to evaluate.
Let's see what's model.template pack.
So model.template pack is null,
and we can see that's when the exception is being raised because,
I've got Model.TemplatePack.icon URL.
So probably it should fix up my code towards it's not going
to throw that null reference exception anymore.
So those are all the debugging tips I have for you today
For.NET Core developers and Visual Studio for Mac.
One additional tip I have
is to check out the docs which are available
at aka.ms/VSMacDocs. Thank you very much.