Learn C# and .NETwith code that was actually run
Tutorials on C#, ASP.NET Core, AI and cloud. Updated posts are tested on .NET 10 and .NET 11, with the real output and the exact error messages.
Popular: .NET 11 upgrade Best AI for C# EF Core errors HttpClient JWT 401
Start here
The most-read guides right now.
C#
The language itself, from C# 12 to C# 15: LINQ, async, generics, pattern matching, nullable reference types and testing with xUnit and Moq.
public union Pet(Cat, Dog, Bird);
Pet pet = new Dog("Rex");
static string Describe(Pet pet) => pet switch
{
Dog d => $"dog {d.Name}",
Cat c => $"cat {c.Name}",
Bird b => $"bird {b.Name}",
};ASP.NET Core
Web APIs on .NET 10 that hold up in production: versioning, auth, error handling, caching, rate limiting, health checks and deployment.
app.MapGet("/products/{id:int}", async (int id, IProductRepository repo, HybridCache cache, CancellationToken ct) =>
{
var product = await cache.GetOrCreateAsync(
$"product:{id}",
(repo, id),
static async (state, token) => await state.repo.GetAsync(state.id, token),
cancellationToken: ct);
return product is null ? Results.NotFound() : Results.Ok(product);
});AI in .NET
AI coding tools for C# developers, and AI inside your app: agents with tools, MCP servers, LLM calls, ML.NET and TorchSharp.
AIAgent agent = chatClient.AsAIAgent(
instructions: "You answer order questions.",
tools: [AIFunctionFactory.Create(OrderTools.GetOrderStatus)]);
var response = await agent.RunAsync("Where is order 1042?");[model call 1] 1 messages, tools: [GetOrderStatus]
[tool ran] GetOrderStatus(1042)
[model call 2] 3 messages, tools: [GetOrderStatus]
[model sees tool result] Order 1042: shipped
reply: Order 1042 has shipped.Cloud
Azure, AWS and Google Cloud from C#: messaging, storage, serverless, infrastructure as code and security.
new Subscription
{
SubscriptionName = subName,
TopicAsTopicName = topicName,
Filter = "attributes.eventType = \"OrderPlaced\""
}Fix an error
Paste-ready answers for the errors developers search most. Each one is reproduced, explained and fixed.
- Dependency injection
Cannot consume scoped service 'IOrderRepository' from singleton 'PriceCache'.See the fix → - EF Core
The instance of entity type 'Product' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked.See the fix → - EF Core migrations
The model for context 'BlogDb' has pending changes. Add a new migration before updating the database.See the fix → - C# compiler
error CS0260: Missing partial modifier on declaration of type 'OrderService'See the fix → - Nullable reference types
warning CS8618: Non-nullable property 'Name' must contain a non-null value when exiting constructor.See the fix → - SQL Server
The certificate chain was issued by an authority that is not trusted.See the fix → - JWT, 401
WWW-Authenticate: Bearer error="invalid_token"See the fix → - .NET 11 upgrade
error CS0103: The name 'CompatibilityVersion' does not exist in the current contextSee the fix →
Recently updated and retested
Rewritten and rerun on the current .NET release.
Show all 58 updated tutorials
- ASP.NET Core Output Caching Not Working? .NET 10 Fixes Nov 2
- Instance of Entity Type Cannot Be Tracked: EF Core Fixes Oct 31
- Microsoft Agent Framework in C#: Tools, Sessions and Errors Oct 31
- ASP.NET Core JWT Authentication (.NET 10): 401 Errors Fixed Oct 31
- dotnet run app.cs in .NET 10: File-Based Apps and 7 Errors Oct 30
- Vertical Slice Architecture in C#: .NET 10 Example & Errors Oct 30
- C# 15 New Features: Examples and Compiler Errors (.NET 11) Oct 29
- Import Excel into SQL Server: OPENROWSET Query and C# Code Oct 29
- Build an MCP Server in C# (.NET 11): stdio, HTTP and Auth Oct 28
- SQL Server ‘Certificate Chain Not Trusted’ Error in .NET Oct 28
- SQL Injection Prevention in C# (.NET 10): 8 Attacks I Ran Oct 28
- EF Core: The Model Has Pending Changes (Causes and Fixes) Oct 27
- 12-Factor App with ASP.NET Core (.NET 10): 7 Errors I Hit Oct 27
- Angular CRUD Example with .NET 10 Web API (and 6 Errors) Oct 26
- Send Email in C# with MailKit (.NET 10): SMTP and Errors Oct 26
- ASP.NET Core Web API Tutorial (.NET 10): CRUD and 7 Errors Oct 26
- ASP.NET Core 11 OpenAPI 3.2: What Breaks and How to Keep 3.1 Oct 26
- CS0260 Missing Partial Modifier: Causes and Fixes in C# Oct 26
- EF Core 11 Breaking Changes: 6 Upgrade Errors and Fixes Oct 25
- Upgrading to .NET 11: 9 Breaking Changes and Fixes Oct 24
- C# 15 Union Types: Examples, Exhaustive Switch and Gotchas Oct 22
- Angular AuthGuard: Functional Route Guards with Examples Oct 21
- Angular 404 on Page Refresh After Deployment: 5 Server Fixes Oct 20
- Google Cloud Pub/Sub with C#: .NET 10 Tutorial and Gotchas Oct 19
- Moq in C# Tutorial: Setup, Verify and Common Errors Oct 19
- IExceptionHandler in ASP.NET Core: Global Error Handling Oct 18
- Repository Pattern in C# with EF Core: Examples and Pitfalls Oct 18
- C# Generics Tutorial (.NET 10): Constraints and Errors Oct 17
- Blazor WebAssembly Tutorial for .NET 10: Build a C# App Oct 17
- C# 14 and C# 13 New Features: Examples and Breaking Changes Oct 14
- C# Source Generators on .NET 10: Tutorial and Common Errors Oct 12
- C# Interface vs Abstract Class: When to Use Each on .NET 10 Oct 12
- C# LINQ Examples on .NET 10: LeftJoin, CountBy and Pitfalls Oct 12
- Enforce HTTPS in ASP.NET Core: Redirects, HSTS and Proxies Oct 12
- C# Nullable Reference Types: Fix CS8618, CS8602 and More Oct 10
- C# Primary Constructors: IDE0290, Pitfalls and Examples Oct 9
- System.Text.Json vs Newtonsoft: .NET 10 Migration Gotchas Oct 8
- HttpClient in .NET 10: IHttpClientFactory, Timeouts, Retries Oct 8
- Compile C# at Runtime in .NET: CSharpCodeProvider to Roslyn Oct 5
- CSharpier vs dotnet format: C# Code Formatting on .NET 10 Oct 5
- gRPC in .NET 10: Service, Client, Streaming and Gotchas Oct 4
- API Versioning in ASP.NET Core: Asp.Versioning on .NET 10 Oct 4
- CQRS with MediatR in ASP.NET Core: A Working Example Oct 1
- ASP.NET Core Rate Limiting: 4 Algorithms Compared on .NET 10 Oct 1
- ASP.NET Core Health Checks on .NET 10: Setup and Gotchas Oct 1
- Repository and Unit of Work Pattern in C# with EF Core Sep 29
- .NET Microservices Architecture with ASP.NET Core (.NET 10) Sep 29
- Angular Date Pipe: Formats, Time Zones and Locales Sep 28
- Hangfire vs Quartz.NET vs BackgroundService in .NET 10 Sep 27
Written and tested by Rajni Kavathiya
I’m a full stack developer. Every updated post says which versions it was tested on and shows the real compiler and runtime output, including the errors I hit along the way.