Workaround for "System.OutOfMemoryException Exception of type 'System.OutOfMemoryException' was thrown." exception

Recently I kept getting System.OutOfMemoryException exception while working on a web application with Visual Studio 2013. 

The full exception message title was as follow:

System.OutOfMemoryException Exception of type 'System.OutOfMemoryException' was thrown.

To resolve this issue, I had to restart Visual Studio or go to the Windows Task Manager and terminate IIS Express process.

This error could happen due to a variety of reasons related to memory consumption of the application.  Looking at my local machine memory, there was always enought memory available! Then what was the cause?

Turns out, Visual Studio uses IIS Exoress 32 bit version by default whereas 64 bit version is available right out there! So as a work around you go to the following path and make Visual studio to use 64 bit version of IISExpress.

Tools | Options | Projects and solutions | Web Projects => Use 64 bit version of IIS Express for websites and projects

Apparently behind the scene Visual Studio changes a flag in windows registry which the key could be found at this path.

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\WebProjects --> Use64BitIISExpress

Have fun programming!

20 Comments

Comments have been disabled for this content.