Integrating AI and machine learning into existing .NET applications
Legacy .NET applications are the quiet engines still powering countless enterprises. You can make them intelligent without rewriting them. Six patterns, a real case and the code.
The headline
Rewrite
6 ways
to add AI to a .NET app without a rewrite
.NETML.NETAzure OpenAIModernization
Legacy .NET applications are the quiet engines still powering countless enterprises. Staying competitive now means going intelligent, and that means adding AI and ML to the systems you already run, without breaking everything.
01 · The problemThe value is clear. The fit is not
Here is what AI and ML can bring to a .NET solution:
- Intelligent predictions: sales, inventory, fraud detection
- Smart document processing: OCR, extraction, sentiment analysis
- Conversational AI: assistants and chatbots over your own data
- Personalized experiences: recommendations, dynamic UI
- Real-time anomaly detection and alerts
The challenge is fitting this into an existing codebase that pays the bills: years of business logic, a database everyone depends on, and no appetite for a rewrite.
02 · The solutionSix ways in, none of them a rewrite
1
AI services over REST
Azure AI, Document Intelligence
2
ML.NET in process
Forecasting, churn, anomalies
3
Containerized models
Python model behind HTTP
Your .NET application
Business logic, database and UI stay as they are
4
Azure OpenAI
Assistants, summaries, RAG
5
Azure Functions
Event-driven AI on upload
6
AI on logs
Application Insights, alerts
1. Call AI services over REST
Keep it simple. Call AI services from your existing code without disturbing the core logic: Azure AI services and Azure OpenAI, AWS AI services such as SageMaker endpoints and Comprehend, or Google Vertex AI. Example: Azure AI Document Intelligence extracts data from scanned invoices and returns JSON straight into your .NET system.
2. Embed ML.NET for in-process predictions
ML.NET is Microsoft’s open-source machine learning library for .NET. You train and consume models in C#, with no Python dependency. It is a strong fit for classification, forecasting and anomaly detection, for example predicting customer churn inside the app.
3. Containerize Python models
Got a model trained in PyTorch, TensorFlow or scikit-learn? Package it as a REST API in Docker, host it on Azure App Service, Container Apps or Kubernetes, and call it over HTTP. Concerns stay separate: the .NET app stays focused, the model runs and scales as its own service.
4. Use Azure OpenAI from .NET
For natural language, summarization and search over your own documents, use Azure OpenAI with the .NET SDK: assistants, email summarizers, knowledge search with RAG, customer support helpers.
5. Event-driven AI with Azure Functions
Modernize step by step. When a user uploads a file, an event triggers a Function that sends it to an AI service and writes the result back to the database. AI is decoupled from the monolith and scales on its own.
6. Put AI on your logs
Feed logs and metrics into Azure Monitor and Application Insights, then apply anomaly detection and forecasting for proactive alerts and predictive monitoring.
03 · In codeDemand forecasting in a WinForms app
Say you have a .NET WinForms application that manages inventory, and you want to forecast product demand. Train a regression model on historical sales with ML.NET, save it as a .zip file, and load it in the app without touching the UI.
csharpvar mlContext = new MLContext();
ITransformer model = mlContext.Model.Load("demand-model.zip", out _);
var engine = mlContext.Model
.CreatePredictionEngine<InventoryData, ForecastPrediction>(model);
var result = engine.Predict(new InventoryData
{
ItemId = "XYZ",
LastMonthSales = 230
});04 · A real caseAsk AI beside a live .NET product
01 · Experience
"Ask AI" chat · streaming over SSE
02 · Orchestration
Agents with tool calling · MCP tools
03 · Knowledge
RAG: embeddings, pgvector · Validated text-to-SQL
04 · Models and runtime
Azure OpenAI · Python, FastAPI · Durable Functions, Container Apps
Every changeEvaluated and traced before release · OpenTelemetry, Phoenix
Already running
.NET SaaS product
ASP.NET, SQL Server, documents customers already store
Result
Answers from PDF, Word, Excel, PowerPoint and SQL, without a rewrite
At AgilityInsights, a SaaS product built on ASP.NET and SQL Server, "Ask AI" now answers questions from customer documents and live databases. The AI runs as its own service in Python and FastAPI with Azure OpenAI, on Durable Functions and Container Apps, beside the existing .NET product. Generated SQL is validated before it runs, and every model or prompt change is evaluated and traced before release. The core product did not need a rewrite.
05 · Watch outThe challenges
| Challenge | What to do |
|---|---|
| Data preparation | Clean, label and structure the data before any model sees it |
| Explainability | Show why a prediction or answer was made. Enterprises need to trust it |
| Performance | External AI calls add latency. Cache, batch, and keep them off the critical path |
| Privacy | Check what data leaves your boundary and keep secrets in Key Vault |
| Versioning | Track model versions and watch for drift over time |
06 · The mindsetStart small, then scale
You do not have to rebuild everything to use AI. Think modular and API-first: ML.NET for native models, REST for external intelligence, Docker for model services, Azure Functions for event-driven work, Azure OpenAI for language. Start with one model, one API and one intelligent workflow. Then scale from there.
One model. One API. One intelligent workflow. Then scale.

Written by
Anuj Gupta
Hands-on software engineer and architect. 23+ years writing enterprise software on .NET, Azure and Oracle Cloud, faster with AI. 21,669 hours on Upwork at a 5.0 rating.