NullGuard.AspNetCore.Diagnostics 1.0.1

dotnet add package NullGuard.AspNetCore.Diagnostics --version 1.0.1
                    
NuGet\Install-Package NullGuard.AspNetCore.Diagnostics -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NullGuard.AspNetCore.Diagnostics" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NullGuard.AspNetCore.Diagnostics" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="NullGuard.AspNetCore.Diagnostics" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NullGuard.AspNetCore.Diagnostics --version 1.0.1
                    
#r "nuget: NullGuard.AspNetCore.Diagnostics, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NullGuard.AspNetCore.Diagnostics@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NullGuard.AspNetCore.Diagnostics&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=NullGuard.AspNetCore.Diagnostics&version=1.0.1
                    
Install as a Cake Tool

🧩 NullGuard.Diagnostics Guide

Advanced NullReferenceException Diagnostic Toolkit for .NET


🇬🇧 English

🎯 Purpose and Core Philosophy

NullGuard.Diagnostics is a specialized .NET diagnostic tool designed to intelligently capture and analyze NullReferenceException (NRE) with rich contextual information — far beyond the standard .NET exception messages.

Unlike typical exception handlers, it filters stack frames to isolate only those from your own project code, removing internal framework noise (like Kestrel, ASP.NET Core internals, or third-party dependencies).

The resulting diagnostic report is structured to maximize debugging efficiency, pinpointing exactly where and why the null occurred.


🧠 Detailed Diagnostic Output

When an NRE is caught and processed, the following structured data is captured:

Field Description Example
Namespace Originating namespace MyApp.Services.User
Class & Method Fully-qualified method name UserService.AuthenticateUser(string username)
Line Number Exact source line 42
Property (Optional) Null property name User.ProfileImage
File Path Optional file and path C:\Projects\MyApp\Services\UserService.cs
FullRoad (Call Chain) Hierarchical call sequence with layer tags [Controller] → [Service] → [Repository]

⚙️ Configuration via NullGuardOptions

Option Type Description Default
ProjectNamespacePrefix string Root namespace used for filtering (Required)
ShowPathFile bool Include file path false
ShowExceptionMessage bool Include original message true
ShowCallChain bool Include FullRoad call analysis true
MaxChainLength int Max depth for call chain 15

🚀 Quick Setup (ASP.NET Core)

Register the service:

builder.Services.AddScoped(sp => new NullGuardService(new NullGuardOptions
{
    ProjectNamespacePrefix = "MyCompany.SuperApp",
    ShowPathFile = true,
    ShowExceptionMessage = true,
    ShowCallChain = true
}));

Register middleware (must be first):

var app = builder.Build();

app.UseMiddleware<NullGuardMiddleware>(); // place this BEFORE UseExceptionHandler()

🧩 Example Diagnostic Output

=====================================================================================
NULLGUARD DIAGNOSTIC REPORT
Timestamp (UTC): 2024-10-27T15:05:12.887Z
Exception Type: System.NullReferenceException

Failing Location Details:
Namespace: MyApp.Infrastructure.Data
Class & Method: DataService.SaveEntity(Entity e)
Line Number: 22
File Name: DataService.cs (Full Path Hidden)
Original Message: Object reference not set to an instance of an object.

FullRoad Call Chain Analysis:
[Controller] -> ApiController.Create(payload)
[Service] -> DataService.SaveEntity(e)
=====================================================================================

🇮🇷 فارسی

🎯 هدف و فلسفه اصلی

کتابخانه NullGuard.Diagnostics برای تشخیص و تحلیل هوشمند خطاهای NullReferenceException طراحی شده است.
در زمان وقوع خطا، این ابزار مسیر فراخوانی را بررسی کرده و فقط بخش‌هایی از کد پروژه‌ی شما را که به خطا مرتبط هستند، فیلتر و گزارش می‌کند.

این گزارش به شما کمک می‌کند دقیقاً بفهمید کدام متد، در چه خطی، و در چه لایه‌ای از معماری برنامه باعث بروز خطا شده است.


⚙️ تنظیمات قابل پیکربندی

ویژگی نوع توضیح پیش‌فرض
ProjectNamespacePrefix string فضای نام اصلی پروژه الزامی
ShowPathFile bool نمایش مسیر فایل false
ShowExceptionMessage bool نمایش پیام خطا true
ShowCallChain bool نمایش مسیر فراخوانی true
MaxChainLength int حداکثر عمق مسیر 15

🚀 راه‌اندازی سریع در ASP.NET Core

ثبت سرویس‌ها:

builder.Services.AddScoped(sp => new NullGuardService(new NullGuardOptions
{
    ProjectNamespacePrefix = "Your.Project.Namespace",
    ShowPathFile = true,
    ShowExceptionMessage = true,
    ShowCallChain = true
}));

ثبت Middleware:

var app = builder.Build();
app.UseMiddleware<NullGuardMiddleware>(); // قبل از سایر Middlewareها

🧩 مثال خروجی گزارش

NULLGUARD DIAGNOSTIC REPORT
Namespace: MyApp.Services
Class & Method: DataService.SaveEntity(Entity e)
Line Number: 22
File Name: DataService.cs
FullRoad: [Controller] -> [Service]

🧮 Advanced Topics

  • Mathematical filtering model
  • Precision/Recall analysis of stack frame filtering
  • JSON serialization for structured logs
  • Middleware interception flow diagram

(See full documentation on GitHub.)


📦 Installation

dotnet add package NullGuard.Diagnostics

© 2025 Mehran Ghaedrahmat — NullGuard.Diagnostics Project
🔗 GitHub Repository

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 240 10/8/2025
1.0.0 233 10/7/2025