No video

Controlling your debugging experience in C#

  Рет қаралды 47,077

Nick Chapsas

Nick Chapsas

Күн бұрын

Check out my courses: dometrain.com
Become a Patreon and get source code access: / nickchapsas
Hello everybody I'm Nick and in this video I will show you how you can customize your debugging experience in C# by using a set of attributes, called the Debugger attributes. Such attributes allow you to change the behavior of the debugger and not only make it easier for you to debug your code easier but also gives you control on how your code consumers also get to debug it.
Don't forget to comment, like and subscribe :)
Social Media:
Follow me on GitHub: bit.ly/ChapsasG...
Follow me on Twitter: bit.ly/ChapsasT...
Connect on LinkedIn: bit.ly/ChapsasL...
Keep coding merch: keepcoding.shop
#csharp #dotnet

Пікірлер: 95
@gdargdar91
@gdargdar91 Жыл бұрын
RootHidden = When you have a class that implements an IEnumerable and delegates it’s job to other enumerable, which it wraps.
@ronsijm
@ronsijm Жыл бұрын
Since you mentioned debugger step through is niche - One thing I used it for is when you create a castle dynamicproxy, and apply interceptors to the object. Otherwise when you try to step into your object methods, it would always jump into the interceptors first, so I `DebuggerStepThough` the interceptors - So it looks like you're directly stepping into the methods (as expected)
@oscareriksson9414
@oscareriksson9414 Жыл бұрын
In VS debugger and in remedybg, I use the watch window a lot, it gives a little better over view if you need to see many variables interact and change values. In the watch window you can also write some code like calling trivial methods or functions or operators. But I think these annotations can be used in combination in a nice way too, or if you dont have watch windows then they seem great!
@phizc
@phizc Жыл бұрын
You can also add the DebuggerDisplayAttribute as an assembly attribute. If you *really* hate yourself and your coworkers you can do for example this: using System.Diagnostics; [assembly: DebuggerDisplay( "420", Target = typeof(int), Type="Something..dunno..")] int x = 69; int y = 80085; int z = 1337; If you hover over one of the ints or look at them in locals or a watch window, it'll say the value is 420. And since it's an assembly attribute, it'll do that for every single int in your project. Happily it doesn't seem to be a way to "inherit" the attributes, so there's that. (until somebody sneaks a code generator into a nuget package to terminate their trustworthiness forever) Of course this can be used for good too. If a BCL type or type from a package has a poor debugging experience, you can fix it yourself. Visual Studio has a bunch of assembly level DDAs in a file called "autoexp" (cs file, but can't type it or YT will think it's a link). The filename is also a terrific search term on Google or whatever 🙂
@MrGTFOplz
@MrGTFOplz Жыл бұрын
I've recently been debugging something using lists of largish objects and I've only been interested in one single property. Was becoming painful expanding it everytime. Cheers!
@shokdiesel1044
@shokdiesel1044 Жыл бұрын
Conditional breakpoint or immediate window. Give it a try.
@phizc
@phizc Жыл бұрын
You can also pin properties and fields in the locals/watch window. It has the same effect as writing a DebuggerDisplay for the type with "Property1 = {Property1}, P2 = {P2}", etc. You can pin multiple prop/fields.
@protox4
@protox4 Жыл бұрын
I use [DebuggerNonUserCode] in my library code, which combines DebuggerHidden and DebuggerStepThrough and can be applied to classes and structs.
@jamesbennett5421
@jamesbennett5421 Жыл бұрын
I’m so used to Nick’s constants being some variant of 69 or 420, that seeing 13 and 37 makes me wonder what I’m missing.
@clonger204
@clonger204 Жыл бұрын
1337 or leet
@phizc
@phizc Жыл бұрын
Had the same thing when he used 80085 awhile ago.
@sasukesarutobi3862
@sasukesarutobi3862 Жыл бұрын
Good debugging tips always pay dividends, especially when it comes to tweaks in setup and annotation so I'll definitely have to have a play around with these in my toy projects. Ever since I found that you could debug individual unit tests in VS2019/2022 (which was a massive boon to my workflow), I've been a convert to the benefits of debugger tricks.
@shokdiesel1044
@shokdiesel1044 Жыл бұрын
Immediate window. The most beneficial debugging tool ever.
@64narayan
@64narayan Жыл бұрын
Make it easier: you can expand object props and press on the icon next to property. It will turn to flag and will be displayed like with [DebuggerDisplay] attribute. Visual Studio has something like this also if I remember correctly
@LordSuprachris
@LordSuprachris Жыл бұрын
I remember using the proxy types at several places in a former job where I had to debug through some very complex types, with loads of properties, sub-arrays of objects, etc., with only a couple of useful ones. It was way much clearer to only see what I needed while debugging than browsing through a complex tree. And for DebuggerStepThrough, I use it on small easy to understand extension methods that I know how they work and don't want to pass through them while debugging because it's most of time irrelevant.
@klocugh12
@klocugh12 Жыл бұрын
RootHidden sounds super useful for classes implementing IEnumerable to collapse inner collection. Proxy seems useful for debugging classes, for which you don't have source to access.
@JustinMinnaar
@JustinMinnaar Жыл бұрын
I use DebuggerStepThrough on a lot of simple constructors, and DebuggerDisplay often. Makes things better.
@ronsijm
@ronsijm Жыл бұрын
Note on DebuggerBrowsableAttribute that is also has a side effect that hidden things won't show up in intellisense anymore (though might depend on the IDE I guess)
@mabakay
@mabakay Жыл бұрын
DebuggerStepThrough very useful in libraries that manage your code. For example, like Promise when using multiple Then and passing lambdas. Stepping through your code using F11 is much more convenient.
@hollow_ego
@hollow_ego Жыл бұрын
I think you got your point across! Alright I'll see myself out...
@harag9
@harag9 Жыл бұрын
Great video, thanks. I use the DebuggerStepThrough when I'm debugging a winforms app, I mainly put it on events that fire, like mouse_move, or form_refresh. Though I tend to not leave it there, just add it in when I'm debuiging.
@francescopolo2621
@francescopolo2621 Жыл бұрын
“You don’t need to debug when you don’t have bugs.” 😂
@FunWithBits
@FunWithBits Жыл бұрын
[DebuggerHidden] on a function with a "System.Diagnostics.Debugger.Break();" will break where that function is called. Useful for functions like VerifyDateFormat(string date){a without it stopping inside the checker function.
@CharlesBurnsPrime
@CharlesBurnsPrime Жыл бұрын
The video title sounded uninteresting, but I watch all of your non-AWS videos. It ended up being interesting, empowering, and at one point I laughed out loud. "Why would you want to do this...? I don't know, but you can!"
@vothaison91
@vothaison91 Жыл бұрын
I've been rocking a $70 asrock board for 3 years now.
@mrx10001
@mrx10001 Жыл бұрын
I wish there was a way to apply these to a class, that you can't edit yourself(external dll or whatever). Would be really nice to be able to make stuff I care about appear at the top of the properties list. Instead of having to search the name. (specifically for unity monobehavoirs, since they have A LOT of fields/props.)
@casperhansen826
@casperhansen826 Жыл бұрын
All these attributes are new to me, but DebuggerDisplay seems usefull, except there are no variable name validation.
@phizc
@phizc Жыл бұрын
Jetbrains Rider probably does since it has intellisense for it. It wouldn't be impossible to write an analyzer for it.
@arjen3112
@arjen3112 Жыл бұрын
that sneaky 1337 @6:55
@verzivull
@verzivull Жыл бұрын
Pin property in "quickwatch" is very helpful. It will do the similar thing you've just shown. Unfortunately, in order to filter properties, I have to copy the "quickwatch" output with the table separation, put it to the google spreadsheet and then filter by something.
@aluced
@aluced Жыл бұрын
Could you make a circular reference with the DebugggerTypeProxy attribute ?
@phizc
@phizc Жыл бұрын
Even if you could, VS at least is smart enough to stop recursing before it runs out of stack.. Ask me how I know 😅
@alfredbroderick653
@alfredbroderick653 Жыл бұрын
Do a video on Debugger Visualizers...
@leandroteles7857
@leandroteles7857 Жыл бұрын
Are these attributes polymorphic (different views for different subclasses), or will the debugger consider only the type of the variable?
@plaam
@plaam Жыл бұрын
Thanks for the content
@caseyspaulding
@caseyspaulding Жыл бұрын
Thank you
@Max_Jacoby
@Max_Jacoby Жыл бұрын
Is there an attribute to allow you to skip exceptions in certain method? I mean to prevent VS from stopping at exception and continue executing catch clause silently?
@darshanghorpade9590
@darshanghorpade9590 Жыл бұрын
Which visual studio extensions are you using for that debug value view?
@theincredibleillmo9385
@theincredibleillmo9385 Жыл бұрын
Hi bro. Is there a way to get a discount for one of your courses for someone who’s is starting with testing in Net Core? Much love
@MassimoRough
@MassimoRough Жыл бұрын
What a twist it would be to have x = 105 and x = 4, then x*y = 420
@user-tk2jy8xr8b
@user-tk2jy8xr8b Жыл бұрын
I hate it when VS won't let you see into Dictionary internals like the hash table and entries
@oleksandrkryklyvets8090
@oleksandrkryklyvets8090 Жыл бұрын
Hi! How do you circle with red rectangle to show smth?
@sayefshahriar
@sayefshahriar 4 ай бұрын
How to debug library functions
@petrucervac8767
@petrucervac8767 Жыл бұрын
These attributes kind of break the separation of concerns
@benya4396
@benya4396 Жыл бұрын
Yes, but it`s a pity that rider or resharper cannot fix the necessary attribytes of the object how VS does it
@mrwillis5339
@mrwillis5339 10 ай бұрын
attributes - there, fixed it for you :)
@MrMikeJJ
@MrMikeJJ Жыл бұрын
Instead of breakpoint on line 3 and stepping over, why don't you just put the breakpoint on line 5?
@ricardotondello
@ricardotondello Жыл бұрын
Hi just out of curiosity, why do you always use the numbers 69 and 420 in allllll your videos? is that a easter egg or something, hahahahahah I love your videos btw.
@walmin73
@walmin73 Жыл бұрын
As a developer, I can tell you that it has to do with how the keys are arranged in the numeric pad. Those numbers are the easiest combination of digits to type. No other meaning at all, trust me.
@nickchapsas
@nickchapsas Жыл бұрын
Walmin is 100% factually correct
@orxanrzazade9570
@orxanrzazade9570 Жыл бұрын
Why do you use Rider instead of Visual Studio?
@tmhchacham
@tmhchacham Жыл бұрын
Very nice!
@MyFuzzyAfterlife
@MyFuzzyAfterlife Жыл бұрын
What program do you use to draw on the screen ? I’ve tried ZoomIt, but that zooms in, and I don’t see a way to disable the zooming.
@nickchapsas
@nickchapsas Жыл бұрын
It's ZoomIt
@ozgunmunar
@ozgunmunar Жыл бұрын
What are the operating system and the program those you use for the video man? Is that Visual Studio 2022 in a Linux distrubition? Thanks for the video.
@Adiu72
@Adiu72 Жыл бұрын
It's a Rider from JetBrains. I do not know the OS.
@ozgunmunar
@ozgunmunar Жыл бұрын
@@Adiu72 Thanks man
@suchoss4770
@suchoss4770 Жыл бұрын
He is using JetBrains Rider running on Windows - but Rider runs even on MAC and Linux
@ozgunmunar
@ozgunmunar Жыл бұрын
@@suchoss4770 thank you so much.
@koldolmen5837
@koldolmen5837 Жыл бұрын
@@ozgunmunar i use it At work, it's amazing
@mikhailkh8560
@mikhailkh8560 Жыл бұрын
We more debugging attributes!!!
@gerakore8948
@gerakore8948 Жыл бұрын
i just output to a textfile
@ali_randomNumberHere
@ali_randomNumberHere Жыл бұрын
🔥
@sodreigor
@sodreigor Жыл бұрын
Hey Nick. You looked somewhat tired in this video. Are you taking proper rest and some time for yourself mate?
@nickchapsas
@nickchapsas Жыл бұрын
I’m very good thanks. This is a video I filmed a few months ago
@cmugy
@cmugy Жыл бұрын
Hi nick
@MarcusKaseder
@MarcusKaseder Жыл бұрын
DebuggerBrowsable is pure evil. It's only there to annoy your colleagues
@stefanbogdanovic590
@stefanbogdanovic590 Жыл бұрын
Great video, but these features are unnecessary IMO, they are OK but do we really need them?
@nickchapsas
@nickchapsas Жыл бұрын
The most useful for me is the first one by far. I've seen many people override the ToString method just to get this experience which is pretty dangerous. The rest are informational and very situational.
@portlyoldman
@portlyoldman Жыл бұрын
Perhaps they were included by the Roslyn compiler team (or similar)as I can imagine debugging those libraries may well have complex debugging scenarios that are aided by these.
@neociber24
@neociber24 Жыл бұрын
Span use that because the inner value is a "pointer", using the Debugger they can show you the list of items in the span
@stefanbogdanovic590
@stefanbogdanovic590 Жыл бұрын
@@nickchapsas Agree with ToString it is much easier debugging with this helper.
@frossen123
@frossen123 Жыл бұрын
For performance reasons i always make a private GetDebuggerDisplay() method so the method evaluator doesn't have to evaluate multiple properties, only the one call in [DebuggerDisplay("GetDebuggerDisplay(),nq")] the method gets optimized away in Release by the compiler
@burningdaylight9171
@burningdaylight9171 Жыл бұрын
Nick))) Could you talk a bit slowly. Please.
Жыл бұрын
Nothing really useful mentinoned in this video.Comments have much useful suggestions.
@jpboy1962
@jpboy1962 Жыл бұрын
Debuggers are evil. Don't use them. Implement excellent logging instead.
@portlyoldman
@portlyoldman Жыл бұрын
Like we used to have to add print statements everywhere before the days of debuggers… no thanks, I’ll take a debugger every time - as well as proper logging, of course.
@jpboy1962
@jpboy1962 Жыл бұрын
@@portlyoldman If you have proper logging why do you need the debugger? What do you do when you have an issue reported in production? Not trying to create a argument. You do what you think is right. I think the debugger is a crutch that facilitates bad software. Not necessary in your case but quite often. I have had clients that had VS installed on there production servers.
@neociber24
@neociber24 Жыл бұрын
Those are different use cases, you use debuggers mostlty during development
@nickchapsas
@nickchapsas Жыл бұрын
I don’t know if you’re trolling or not 😂
@portlyoldman
@portlyoldman Жыл бұрын
@@nickchapsas - it all lads tithe fun though, doesn't it ! Freddx L has it right though. Logging is for Production and Debuggers are for dev. mostly...
@grgr8238
@grgr8238 Жыл бұрын
Can you stop with all these shit calle programming, you cant program anything without bugs and problèms with each line of code
@ME-dg5np
@ME-dg5np Жыл бұрын
Fantastic !!
What is Span in C# and why you should be using it
15:15
Nick Chapsas
Рет қаралды 252 М.
Don't throw exceptions in C#. Do this instead
18:13
Nick Chapsas
Рет қаралды 256 М.
Кадр сыртындағы қызықтар | Келінжан
00:16
Harley Quinn's plan for revenge!!!#Harley Quinn #joker
00:49
Harley Quinn with the Joker
Рет қаралды 33 МЛН
黑天使遇到什么了?#short #angel #clown
00:34
Super Beauty team
Рет қаралды 43 МЛН
Tips and Tricks for Debugging JavaScript
13:03
James Q Quick
Рет қаралды 409 М.
Settling the Biggest Await Async Debate in .NET
14:47
Nick Chapsas
Рет қаралды 142 М.
3 .NET "Best Practices" I Changed My Mind About
10:16
Nick Chapsas
Рет қаралды 102 М.
How IEnumerable can kill your performance in C#
11:02
Nick Chapsas
Рет қаралды 116 М.
8 await async mistakes that you SHOULD avoid in .NET
21:13
Nick Chapsas
Рет қаралды 311 М.
Stop Using IEnumerable The Wrong Way in .NET! | Code Cop #019
10:10
The CORRECT way to implement Retries in .NET
17:01
Nick Chapsas
Рет қаралды 87 М.
Writing C# without allocating ANY memory
19:36
Nick Chapsas
Рет қаралды 147 М.
Debugging Like A Pro
5:48
ByteByteGo
Рет қаралды 104 М.
Кадр сыртындағы қызықтар | Келінжан
00:16