System.OutOfMemoryException thrown while building a large C# solution using Visual Studio 2005 SP1 IDE.

This article has been archived. It is offered "as is" and will no longer be updated.
Source: Microsoft Support
RAPID PUBLISHING
RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.
Action
Created a large managed solution using Visual Studio that contains many managed projects inside.  The size of the solution can be greater than 300 MB depending on what's in each project in the solution.  The size can variety due to the nature of the problem. 
Result


When building such a large solution from the IDE, the build may fail with OutOfMemoryException. The output window contains the following error message.


The "GenerateResource" task failed unexpectedly.
System.OutOfMemoryException: Exception of type "System.OutOfMemoryException" was thrown.



Cause
The solution size is the root cause of the problem.  This is a limitation memory usage in any process.  What is happening here is that the IDE is loading all files into memory and running out of process memory to continue due to the size of the solution.  A process can ideally allocate 4 GB memory in 43 bit, but that is divided into 2 GB for user and 2 for kernel.  When the process gets close to 2 GB memory usage it will throw OutOfMemory exception.
Resolution
Reducing the solution size by removing one project or a few projects will resolve the issue.  Having many projects in a single solution is not good practice as well.
More Information
Structuring Solutions and Projectshttp://msdn2.microsoft.com/en-us/library/ms998208.aspx

DISCLAIMER
MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.
Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.
Properties

Article ID: 949755 - Last Review: 01/15/2015 08:01:00 - Revision: 2.0

  • Microsoft Visual Studio 2005 Standard Edition
  • Microsoft Visual Studio 2008 Standard Edition
  • kbnosurvey kbarchive kbnomt kbrapidpub KB949755
Feedback