System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown
The process couldn’t allocate memory — large in-memory data, leaks, 32-bit process limits, or container memory limits.
Seen on:
.NET
Meaning
Loading whole files/tables into memory, huge strings/StringBuilders, caching without limits, or running as 32-bit (Prefer 32-bit) cause it. In containers the GC heap limit follows the memory limit.
Common causes
- Loading large datasets/files fully into memory
- Memory leak (static caches, event handlers)
- 32-bit process (Prefer 32-bit)
- Container memory limit
⚡ Quick fix
- Stream data (IAsyncEnumerable, FileStream)
- Use dotnet-counters/dotnet-dump to find what grows
- Build as 64-bit; raise container limit if justified
Detailed fix by platform
Shell
- csharp
dotnet-counters monitor -p <pid> System.Runtime dotnet-dump collect -p <pid>
How to diagnose
- Growth — GC heap over time
- Bitness — 32-bit?
- Limits — Container memory
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in .NET
- NullReferenceException System.NullReferenceException: Object reference not set to an instance of an object
- FileNotFoundException assembly Could not load file or assembly 'X, Version=…' or one of its dependencies
- InvalidOperationException InvalidOperationException: Unable to resolve service for type 'X' while attempting to activate 'Y'
Other ways to find it
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026