AI in .NET Tutorials: LLMs, Agents, RAG and ML.NET

Last updated: October 6, 2026

Every AI and machine learning article on this site for C# and .NET developers: calling large language models from C#, building agents and RAG chatbots, running models locally, training your own with ML.NET and TorchSharp, and AI tools for writing and reviewing C# code. Posts with a tested mark were rewritten from a working project; the others are tutorials that have not been re-run yet, so check package versions before you copy code.

Start here

Your situationRead this
CS0246: The type or namespace name 'AnalyzeDocumentContent' could not be found after updating Azure.AI.DocumentIntelligenceDocument Intelligence: the GA breaking changes
An invoice total comes back null because the field is number, not currencyDocument Intelligence: amounts gotcha
Choosing between GitHub Copilot, Claude Code, Codex, Cursor and JetBrains AI for C#AI code generation tools compared
You want a chatbot over your own documentsRAG chatbot with Semantic Kernel
You want an LLM without sending data to a cloud APILocal AI with Ollama
You want to train a model on your own data in C#ML.NET: your first model

1. Call an LLM from C#

Start with the first one if you use OpenAI directly, the second if your company is on Azure.

2. Agents, RAG and search

3. Run models locally and process documents

  • Local AI with Ollama: calling Ollama with HttpClient and OllamaSharp, streaming, ASP.NET Core integration and the OpenAI-compatible endpoint.
  • Azure AI Document Intelligence: the SDK 1.0 GA breaking changes, invoice extraction with real output, confidence scores, long-running operations and free-tier limits. (rewritten; SDK run against Microsoft’s sample responses, no live Azure calls)

4. Train your own models

ML.NET for classic machine learning inside a .NET app, TorchSharp when you need PyTorch-style deep learning.

  • ML.NET: your first model: data models, pipeline, training, evaluation, saving the model, PredictionEnginePool and AutoML.
  • ML.NET image classification: loading images from disk, training, honest evaluation and serving the model from ASP.NET Core.
  • NLP with ML.NET: sentiment analysis, text featurization, multi-class classification and transformer-based text classification.
  • Recommendation system with ML.NET: collaborative filtering with matrix factorization, top-N recommendations and what the metrics mean.
  • TorchSharp deep learning: tensors, a first network, custom modules, mini-batch training, memory management and loading PyTorch models.

5. AI tools for writing C#

  • Best AI code generation tools for C#: Copilot, Claude Code, Codex, Cursor, JetBrains AI and Kiro compared, with three generated samples run and the bugs found in them. (rewritten; samples run on .NET 10)
  • GitHub Copilot in Visual Studio: setup, inline completions, Copilot Chat for refactoring and tests, and agent mode.
  • GitHub Copilot tips for C#: steering with comments and signatures, custom instructions for a .NET repo, agent mode with tests as guardrails and the usual mistakes.
  • AI code review in C#: a review bot that reads the diff, posts comments and runs in GitHub Actions, plus Roslyn for extra context.

Related guides

Hosting an AI feature behind an API? The ASP.NET Core tutorials guide covers rate limiting, health checks and background jobs. For the cloud services these posts call, see the cloud and security guide.