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.
Exception of type 'System.OutOfMemoryException' was thrownInsufficient memory to continue the execution of the program 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
- FileNotFoundException assembly Could not load file or assembly 'X, Version=…' or one of its dependencies
- Unable to cast object of type System.InvalidCastException: Unable to cast object of type 'X' to type 'Y'
- NullReferenceException System.NullReferenceException: Object reference not set to an instance of an object
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 12 Oct 2026