Ali Hamza Ansari

Ali Hamza Ansari

Meet Ali, a talented .NET developer from Pakistan. Besides blogging, Ali works for a range of international customers doing everything from C# to Azure.

74 posts •
Why AI-Generated code still needs tests

AI tools turn ideas into working apps in minutes, but they don't know your business rules, architecture or security requirements. Generated code can look right and still hide gaps, so it needs tests and human review. This post covers where it falls short and how to use AI safely. ...

Memory-efficient JSON in .NET 10 web APIs with PipeReader

Deserializing a JSON payload with a million objects strains memory and the garbage collector. .NET 10 adds PipeReader support to System.Text.Json, letting the serializer read straight from a pipeline. This post benchmarks it against streams on execution time, allocations, and GC collections. ...

Designing APIs for AI agents: your API has a new user

AI agents are a new kind of API consumer: they call endpoints, retry requests, and chain multi-step workflows on their own. This post covers practical ASP.NET Core patterns for building agent-ready APIs, including DTOs, idempotency, pagination, machine-readable errors, auth, and llms.txt. ...

Swagger vs. Scalar: A comparison for ASP.NET Core developers

Swagger UI used to ship by default with ASP.NET Core API projects, but recent .NET versions replaced it with a bare OpenAPI document. This post compares Swagger and Scalar as documentation UIs, walks through setting up each one in .NET 10, and covers when to pick one over the other. ...

Using C# 14 to build "Smart records" for config & settings models

Traditional config classes let properties be mutated anywhere and accept invalid values with no warning. This article shows how to use C# 14's new extension-block syntax with records to build "smart records" - immutable, self-validating configuration models for cleaner, safer ASP.NET Core apps. ...

Getting started with RAG in ASP.NET Core

AI hype is everywhere, but where do you start with .NET? In this beginner-friendly post, we build a simple RAG pipeline in an ASP.NET Core Web API using keyword matching instead of embeddings, covering retrieve, augment, and generate end to end, with vector embeddings saved for a later post. ...

Building your first MCP server in ASP.NET Core

The Model Context Protocol (MCP) gives AI assistants a standardized way to interact with software. Learn how to construct your first MCP server in ASP.NET Core, expose C# tools using standard attributes, and test your setup end-to-end with the official MCP Inspector. ...

What happens when you call await? A step-by-step runtime breakdown

This step-by-step breakdown shows what happens when C# hits an await: the compiler generates an IAsyncStateMachine struct with a MoveNext() method splitting code at each await, using a GetDataCountAsync example with two awaited HttpClient calls to show how OnCompleted frees the calling thread. ...

Modern authentication in ASP.NET Core with 2FA and passkey

This walkthrough builds a .NET 10 ASP.NET Core Web API (TwoFaNET10) implementing two-factor authentication and WebAuthn/FIDO2 passkey login, using Microsoft.AspNetCore.Identity.EntityFrameworkCore with Npgsql PostgreSQL, JWT bearer tokens, and a custom ApplicationUser extending IdentityUser. ...