Best 9 Effective Debugging Tips for .NET Developer

Best 9 Effective Debugging Tips for .NET Developer

It is hard to build up a program that is free from bugs. This is the reason it is essential to bridle devices and methods to substance out the bugs implanted inside your codebase. 

Most of the dot net developers in India use a portion of the popular debugging methods and have some remarkable tools and strategies to debug its applications. We’ll discover a few latest techniques and tools that can help in debugging for .NET

Augury 

Utilizing Augury, you can see the part tree of Angular applications, you can see the present condition of segments, and you can see how segments respond to state changes. 

You can see changes to segments state progressively. 

Divination can likewise be utilized to see the source of every part by tapping on the view source interface close to every segment. 

At the point when the view source button is clicked, the source for the part is shown, demonstrating the techniques, state and information bound to the segment. 

The segment pecking order and the part’s conditions can be seen in the Injector chart tab. 

Debugger 

Using a debugger statement in your code will cause a breakpoint in the application to set the statement.

For instance, if we have to see the information being passed to a function, we place the debugger explanation at the passage purpose of the function: 

addToCart(item) { 

debugger; 

this.store.dispatch(new AddToCart(item)); 

this.inCart = valid; 

} 

TypeScript 

You would then be able to see the information sent on each function call. 

ng test 

This is a helpful DevTools order to review the present condition of any segment inside the part tree. To utilize the order, visit the DevTools. In the Inspector tab, select any Angular component, at that point explore to the comfort tab and run the accompanying order: 

ng.probe($0).componentInstance 

Slam 

The ng.probe function takes a single parameter: $0; this is a DevTools easy route for survey the keep going chosen component on the Inspector tab. Different parameters that can be passed to ng.probe are $1, $2, $3, $4, each meaning the last four chose components in the Inspector tab. 

Editors 

To begin in VS Code, the initial step is to introduce the Debugger for Chrome augmentation. You can look through the augmentations tab, and it’ll spring up: 

On the off chance that the augmentation hasn’t been introduced beforehand, you should see an introduce button right where the uninstall button is in the screen capture. At the point when the establishment is finished, reload the editorial manager window. 

Following stage is to design the dispatch content: launch.json. Versus Code has a few presets, so you genuinely don’t need to stress over composition without any preparation. Go to the troubleshoot tab as an afterthought bar, the one with the bug symbol. After that, right-click and select the chrome preset. This will help you to get the dispatch content.

Tap 

Debugging observables is purposely precarious — no one can tell what worth will be going through, particularly when channelling services. It very well may be put between funnelled services to perform symptoms like logging the qualities channeled through it straightforwardly. 

import { of } from ‘rxjs’; 

import { tap, map } from ‘rxjs/administrators’; 

const levels = of(2, 4, 6, 8); 

const divisor = evens.pipe( 

tap(val => console.log(‘BEFORE MAP: ${val}’)), 

map(val => val/2), 

tap(val => console.log(‘AFTER MAP: ${val}’)) 

); 

TypeScript 

At the point when the divisor esteem is run nonconcurrently, both the present worth and the changing qualities are logged. 

Prior to MAP: 2 

AFTER MAP: 1 

Prior to MAP: 4 

AFTER MAP: 2 

Prior to MAP: 6 

AFTER MAP: 3 

Prior to MAP: 8 

AFTER MAP: 4 

Profiler 

Precise has a worked in profiler that records the measure of time it takes to change identification all through the application. To empower the profiler, you need to empower troubleshoot apparatuses in your Angular application. Update your main.ts document to be like the scrap underneath: 

import { enableProdMode, ApplicationRef } from ‘@angular/center’; 

import { platformBrowserDynamic } from ‘@angular/stage program dynamic’; 

import { AppModule } from ‘./application/app.module’; 

import { condition } from ‘./situations/condition’; 

import { enableDebugTools } from ‘@angular/stage program’; 

if (environment.production) { 

enableProdMode(); 

} 

platformBrowserDynamic().bootstrapModule(AppModule).then(module => { 

let applicationRef = module.injector.get(ApplicationRef); 

let appComponent = applicationRef.components[0]; 

enableDebugTools(appComponent); 

}) 

.catch(err => console.error(err)); 

TypeScript 

In the wake of rolling out this improvement, you can feel free to run the accompanying order in your DevTools support: 

ng.profiler.timeChangeDetection() 

Reassure Debugging 

You can’t finish the rundown without referencing one of the best debugging strategies, logging items to the reassure. It is ordinarily utilized being developed conditions to imagine information streaming inside the application. There are various strategies for presenting information on the encourage; the generally utilized ones are console.log, console.warn, and console.error. 

You can without much of a stretch post information to the support when occasions are triggered by logging the information from the occasion utilizing any of the reassure strategies: 

addToCart(item: Product) { 

console.log(item); 

this.store.dispatch(new AddToCart(item)); 

this.inCart = valid; 

} 

TypeScript 

At the point when a thing is added to the truck, the thing is logged to the reassuring. 

You can post blunders from your application to the comfort also to monitor them utilizing console.error. 

addToCart(item: Product) { 

attempt { 

console.log(item); 

this.store.dispatch(new AddToCart(item)); 

this.inCart = valid; 

toss new Error(‘an mistake occurred’); 

} get (e) { 

console.error(e); 

} 

} 

TypeScript 

You can likewise channel reassure levels to show just blunders or logs, and so on. It helps clean up the comfort while scanning for information logged to the support utilizing a specific strategy. 

You can peruse more on the support strategies here. 

Conclusion

You can’t get away from bugs regardless of how quick you run or, for this situation, how great your codebase is, so picking a debugging procedure that works for you is indispensable.

Leave a Comment

Scroll to Top