Ctrl+Q, search for feature “exception settings” -> enable setting below
Category: .NET
dnSpy – .NET debugger and assembly editor
dnSpy is a debugger and .NET assembly editor. You can use it to edit and debug assemblies even if you don’t have any source code available. Main features: Debug .NET and Unity assemblies Edit .NET and Unity assemblies Light and dark themes
Debugger
- Debug .NET Framework, .NET and Unity game assemblies, no source code required
- Set breakpoints and step into any assembly
- Locals, watch, autos windows
- Variables windows support saving variables (eg. decrypted byte arrays) to disk or view them in the hex editor (memory window)
- Object IDs
- Multiple processes can be debugged at the same time
- Break on module load
- Tracepoints and conditional breakpoints
- Export/import breakpoints and tracepoints
- Call stack, threads, modules, processes windows
- Break on thrown exceptions (1st chance)
- Variables windows support evaluating C# / Visual Basic expressions
- Dynamic modules can be debugged (but not dynamic methods due to CLR limitations)
- Output window logs various debugging events, and it shows timestamps by default 🙂
- Assemblies that decrypt themselves at runtime can be debugged, dnSpy will use the in-memory image. You can also force dnSpy to always use in-memory images instead of disk files.
- Public API, you can write an extension or use the C# Interactive window to control the debugger
Load/stress testing .NET API with Apache JMeter
In this article, you’re going to dive into the universe of Apache JMeter, one of the most used agnostic load test tools in the software development community by testing it against a REST application created in ASP.NET.
ClosedXML – .NET library for Excel files
ClosedXML is a .NET library for reading, manipulating and writing Excel 2007+ (.xlsx, .xlsm) files. It aims to provide an intuitive and user-friendly interface to dealing with the underlying OpenXML API.
Source: ClosedXML
License: MIT / Open source project
Doc: https://closedxml.readthedocs.io/en/latest/index.html
Wiki: https://github.com/closedxml/closedxml/wiki
ClosedXML is a wrapper of the offical .NET Open XML SDK:
https://github.com/dotnet/Open-XML-SDK
Try the new System.Text.Json source generator – .NET Blog
In .NET 6.0, we are shipping a new C# source generator to help improve the performance of applications that use System.Text.Json. In this post, I’ll go over why we built it, how it works, and what benefits you can experience in your application.
Source: Try the new System.Text.Json source generator – .NET Blog
Task Async handling cancellation – Cancellation in Managed Threads | Microsoft Docs
How to handle cancellation of x number of running background tasks.
Source: Cancellation in Managed Threads | Microsoft Docs
Code examples: https://docs.microsoft.com/en-us/dotnet/standard/threading/cancellation-in-managed-threads#code-example
SharpLab Online Tool – Reveal what happens during compilation of C#
SharpLab is a .NET code playground that shows intermediate steps and results of code compilation. Some language features are thin wrappers on top of other features — e.g.Â
using()
 becomesÂtry/finally
. SharpLab allows you to see the code as compiler sees it, and get a better understanding of .NET languages.Recent versions include experimental support for running code, with some limitations.
Online tool: SharpLab
Retry and fault handling in C# .NET
Sometimes you need to implement some sort of retry logic if an error occurs in a c# program.
Existing libraries for retry and fault handling:
Polly
http://www.thepollyproject.org/
CircuitBreaker.Net
https://github.com/alexandrnikitin/CircuitBreaker.Net
Read more about the related Circuit Breaker pattern:
CircuitBreaker
http://martinfowler.com/bliki/CircuitBreaker.html
Circuit Breaker Pattern
https://msdn.microsoft.com/en-us/library/dn589784.aspx
Error handling and policies in general:
https://en.wikipedia.org/wiki/Exception_handling#Restarts_separate_mechanism_from_policy
https://docs.microsoft.com/en-us/dotnet/standard/exceptions/
https://stackify.com/csharp-exception-handling-best-practices/
Working with Equals() and GetHashCode() to compare your objects in C#
In general these interfaces and methods are good to implement when working with comparing objects of the same type in C#:
Interfaces:
System.IEquatable<T> – strongly typed implementation
IComparable<T> – strongly typed implementation
Override methods:
An override of Object.Equals(Object).
An override of Object.GetHashCode().
An override of Object.ToString() is usually a good idea.
Operator overloads for operator == and operator !=.
General rule of GetHashCode():
If two objects is equal then their hashvalues should be the same.
E.g.:
If Equals == true then
x.GetHashCode() == y.GetHashCode()
GetHashCode() is frequently used by collections like Dictionary<Key, Value> and HashSet<T>
Links:
Guidelines for Overloading Equals() and Operator == (C# Programming Guide)
https://msdn.microsoft.com/en-us/library/ms173147.aspx
- How to best implement Equals for custom types?
http://stackoverflow.com/questions/567642 - Implement value objects
https://docs.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrspatterns/implement-value-objects - C# – Always valid value objects
https://danielwertheim.se/csharp-always-valid-value-objects/ - What is the best algorithm for overriding GetHashCode?
https://stackoverflow.com/questions/263400
c# – LINQ’s Distinct() on a particular property
EDIT: This is now part of MoreLINQ.
What you need is a “distinct-by” effectively. I don’t believe it’s part of LINQ as it stands, although it’s fairly easy to write:
public static class EnumerableExtensions { public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) { HashSet<TKey> seenKeys = new HashSet<TKey>(); foreach (TSource element in source) { if (seenKeys.Add(keySelector(element))) { yield return element; } } } }
Source: c# – LINQ’s Distinct() on a particular property – Stack Overflow