In C#, you are allowed to set certain behavior pro-grammatically and the debugger follow the same during run time. The C# has a unique feature called Attribute that is a declarative tag is used to convey information to debugger run-time behavior with various elements like classes, methods, structures, enumerators, assemblies in your program. In C#, attributes provide a powerful method of associating declarative information with C# code (types, methods, properties, etc). In this article learn how to use DubuggerHidden attribute declarative that hides methods from debugger in c#.In the Visual Studio, you have already aware benefits of using break points in your code. The code execution will automatically suspended or paused when execution control hit your break points and application goes into debugging mode. Further you will have several options to debug your code easily. In debug mode, you can see the snapshot of objects, call stack, etc. As you have already seen, the call stack contains the trace of all calling methods, exception trace, exception message etc.
Assume that your code contains few methods which just bypass call to other methods and no other business code is written that help you in debugging. For such methods you expect the debugger not to hit or stepping in while debugging. However it may decrease in debugging time.
For example, the below code has two break points at method AddTwoNumbers and method Add respectively. In method AddTwoNumbers no additional business logic written and simply call Add method to calculate addition of two numbers. In this case, typical debugging hit both the break points
In the below video, you can see the normal behavior of the .Net debugger. All the breakpoints encountered are hit in the code while debugging.
Hide methods from debugger in C#:
If any method enclosed with the DebuggerHidden attribute then, Visual Studio debugger will ignore that method during debugging. In this case, if any break points inserted in this method will never hit.
– Article ends here –