# "System.OutOfMemoryException was thrown" adding c++ classes or generating visual studio project files ( UE 5.1 )

**URL:** <https://forums.unrealengine.com/t/system-outofmemoryexception-was-thrown-adding-c-classes-or-generating-visual-studio-project-files-ue-5-1/722613>\
**Category:** C++\
**Tags:** UE-5, unreal-engine, compile-error, bug-report, CPP, question\
**Created:** [December 6, 2022, 1:36pm UTC](https://forums.unrealengine.com/t/system-outofmemoryexception-was-thrown-adding-c-classes-or-generating-visual-studio-project-files-ue-5-1/722613 "2022-12-06T13:36:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ciullss\_7Games](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ciullss_7games/32/903355_2.png) [@Ciullss\_7Games](https://forums.unrealengine.com/u/Ciullss_7Games)\
**Post date:** [December 6, 2022, 1:36pm UTC](https://forums.unrealengine.com/t/system-outofmemoryexception-was-thrown-adding-c-classes-or-generating-visual-studio-project-files-ue-5-1/722613/1 "2022-12-06T13:36:29Z")

</div>

When I try to add a c++ class or generate visual studio project files, I get this error message.  
On unreal engine 5.0.3 I don’t have this problem

```auto
Binding IntelliSense data... 100%
Writing project files...
Writing project files... 33%
Unhandled exception: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Text.StringBuilder.ToString()
   at UnrealBuildTool.VCProjectFile.WriteProjectFile(List`1 InPlatforms, List`1 InConfigurations, PlatformProjectGeneratorCollection PlatformProjectGenerators, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\VisualStudio\VCProject.cs:line 1381
   at UnrealBuildTool.ProjectFileGenerator.WriteProjectFiles(PlatformProjectGeneratorCollection PlatformProjectGenerators, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\ProjectFileGenerator.cs:line 2812
   at UnrealBuildTool.VCProjectFileGenerator.WriteProjectFiles(PlatformProjectGeneratorCollection PlatformProjectGenerators, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\VisualStudio\VCProjectFileGenerator.cs:line 480
   at UnrealBuildTool.ProjectFileGenerator.GenerateProjectFiles(PlatformProjectGeneratorCollection PlatformProjectGenerators, String[] Arguments, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\ProjectFileGenerator.cs:line 1176
   at UnrealBuildTool.GenerateProjectFilesMode.Execute(CommandLineArguments Arguments, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Modes\GenerateProjectFilesMode.cs:line 233
   at UnrealBuildTool.UnrealBuildTool.Main(String[] ArgumentsArray) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.cs:line 648

```

Has anyone had my same problem? If yes, how did you solve it?

---

<div class="post-metadata">

**Author:** ![Ciullss\_7Games](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ciullss_7games/32/903355_2.png) [@Ciullss\_7Games](https://forums.unrealengine.com/u/Ciullss_7Games)\
**Post date:** [December 6, 2022, 3:49pm UTC](https://forums.unrealengine.com/t/system-outofmemoryexception-was-thrown-adding-c-classes-or-generating-visual-studio-project-files-ue-5-1/722613/2 "2022-12-06T15:49:10Z")

</div>

To fix this, go to C:/Program Files/dotnet and cut the folder and paste it into C:/Programs (x86).  
If a dotnet folder already exists in x86, delete it and replace it with the one you previously cut.

---

<div class="post-metadata">

**Author:** ![iNiK\_Ko](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/inik_ko/32/546575_2.png) [@iNiK\_Ko](https://forums.unrealengine.com/u/iNiK_Ko)\
**Post date:** [December 7, 2022, 2:55am UTC](https://forums.unrealengine.com/t/system-outofmemoryexception-was-thrown-adding-c-classes-or-generating-visual-studio-project-files-ue-5-1/722613/3 "2022-12-07T02:55:23Z")

</div>

Thank you!!! , this fixed it idk why but thanks

---

<div class="post-metadata">

**Author:** ![Ciullss\_7Games](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ciullss_7games/32/903355_2.png) [@Ciullss\_7Games](https://forums.unrealengine.com/u/Ciullss_7Games)\
**Post date:** [December 7, 2022, 5:54pm UTC](https://forums.unrealengine.com/t/system-outofmemoryexception-was-thrown-adding-c-classes-or-generating-visual-studio-project-files-ue-5-1/722613/5 "2022-12-07T17:54:13Z")

</div>

I’m happy to have helped you, I’ve been a week figuring out where the problem was

---

<div class="post-metadata">

**Author:** ![Mackinder](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mackinder](https://forums.unrealengine.com/u/Mackinder)\
**Post date:** [December 8, 2022, 7:48am UTC](https://forums.unrealengine.com/t/system-outofmemoryexception-was-thrown-adding-c-classes-or-generating-visual-studio-project-files-ue-5-1/722613/6 "2022-12-08T07:48:47Z")

</div>

This solution might work for this specific problem, but it’ll absolutely break any other programs that are using .NET components that are installed in the x86 directory.

Maybe instead of that you could have found what .NET was installed in the x86 directory and made sure to install the x64 versions instead.

---

<div class="post-metadata">

**Author:** ![Timmy\_Sib](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Timmy\_Sib](https://forums.unrealengine.com/u/Timmy_Sib)\
**Post date:** [December 8, 2022, 8:01pm UTC](https://forums.unrealengine.com/t/system-outofmemoryexception-was-thrown-adding-c-classes-or-generating-visual-studio-project-files-ue-5-1/722613/7 "2022-12-08T20:01:53Z")

</div>

Thank you very much! You helped a lot 🙂

---

<div class="post-metadata">

**Author:** ![zipiezz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zipiezz](https://forums.unrealengine.com/u/zipiezz)\
**Post date:** [January 5, 2023, 4:04pm UTC](https://forums.unrealengine.com/t/system-outofmemoryexception-was-thrown-adding-c-classes-or-generating-visual-studio-project-files-ue-5-1/722613/8 "2023-01-05T16:04:09Z")

</div>

Nort solved at all, I can’t believe no offical answer comes for this issue

---

<div class="post-metadata">

**Author:** ![AfaqaLev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AfaqaLev](https://forums.unrealengine.com/u/AfaqaLev)\
**Post date:** [January 15, 2023, 12:36am UTC](https://forums.unrealengine.com/t/system-outofmemoryexception-was-thrown-adding-c-classes-or-generating-visual-studio-project-files-ue-5-1/722613/9 "2023-01-15T00:36:31Z")

</div>

Had the same problem on clean install of the windows, the proposed solution fixed the error but I think this problem needs to be addressed properly

---

<div class="post-metadata">

**Author:** ![Sparkwit](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sparkwit](https://forums.unrealengine.com/u/Sparkwit)\
**Post date:** [February 4, 2023, 3:35am UTC](https://forums.unrealengine.com/t/system-outofmemoryexception-was-thrown-adding-c-classes-or-generating-visual-studio-project-files-ue-5-1/722613/10 "2023-02-04T03:35:44Z")

</div>

I am also running into this issue on a clean install and while even opening a blank project in the Unreal Editor 5.1. I can’t seem to open any kind of project without running into this exception.

I’ve tried converting a 4.7 project in place (in Editor)  
…tried copying a 4.7 project to a 5.1 project (in Editor)  
…tried generating VS files for project from right click on uproject  
…tried moving dotnet folder in Program Files as described in “solution”  
…installed all suggested workloads sugested for VS installation  
…even a missing component I had for desktop C++ development  
…tried opening a blank 5.1 project with no modules installed

Always the same exception output, always at 33% on “Writing project files”.

```auto
Running D:/Dev/UE5/UE_5.1/Engine/Build/BatchFiles/Build.bat
...
Discovering modules, targets and source code for project...
Binding IntelliSense data...
Binding IntelliSense data... 100%
Writing project files...
Writing project files... 33%
Unhandled exception: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Text.StringBuilder.ToString()
   at UnrealBuildTool.VCProjectFile.WriteProjectFile(List`1 InPlatforms, List`1 InConfigurations, PlatformProjectGeneratorCollection PlatformProjectGenerators, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\VisualStudio\VCProject.cs:line 1381
   at UnrealBuildTool.ProjectFileGenerator.WriteProjectFiles(PlatformProjectGeneratorCollection PlatformProjectGenerators, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\ProjectFileGenerator.cs:line 2812
   at UnrealBuildTool.VCProjectFileGenerator.WriteProjectFiles(PlatformProjectGeneratorCollection PlatformProjectGenerators, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\VisualStudio\VCProjectFileGenerator.cs:line 480
   at UnrealBuildTool.ProjectFileGenerator.GenerateProjectFiles(PlatformProjectGeneratorCollection PlatformProjectGenerators, String[] Arguments, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\ProjectFileGenerator.cs:line 1176
   at UnrealBuildTool.GenerateProjectFilesMode.Execute(CommandLineArguments Arguments, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Modes\GenerateProjectFilesMode.cs:line 233
   at UnrealBuildTool.UnrealBuildTool.Main(String[] ArgumentsArray) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.cs:line 648

```

I’m running with hardware that should not be an issue, and have a hunch it’s still an issue in my environment settings.

I can open the 4.27 editor version without this issue.

---

<div class="post-metadata">

**Author:** ![BlastSentryDivision](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/blastsentrydivision/32/1031270_2.png) [@BlastSentryDivision](https://forums.unrealengine.com/u/BlastSentryDivision)\
**Post date:** [February 4, 2023, 6:01pm UTC](https://forums.unrealengine.com/t/system-outofmemoryexception-was-thrown-adding-c-classes-or-generating-visual-studio-project-files-ue-5-1/722613/11 "2023-02-04T18:01:52Z")

</div>

Deleting the dotnet folder in x86 wasn’t sufficient for me. I also had to clear the folder’s entry in the Windows’ Environment Variables

---

<div class="post-metadata">

**Author:** ![DryreL](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dryrel/32/1042339_2.png) [@DryreL](https://forums.unrealengine.com/u/DryreL)\
**Post date:** [February 21, 2023, 10:44am UTC](https://forums.unrealengine.com/t/system-outofmemoryexception-was-thrown-adding-c-classes-or-generating-visual-studio-project-files-ue-5-1/722613/12 "2023-02-21T10:44:31Z")

</div>

Thank you!!

---

<div class="post-metadata">

**Author:** ![Rookirab](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rookirab](https://forums.unrealengine.com/u/Rookirab)\
**Post date:** [March 22, 2023, 3:53pm UTC](https://forums.unrealengine.com/t/system-outofmemoryexception-was-thrown-adding-c-classes-or-generating-visual-studio-project-files-ue-5-1/722613/13 "2023-03-22T15:53:57Z")

</div>

I tried to delete the dotnet folder from c:\Program Files (x86) but Windows prevented me because the folder is being opened by other programs.

I’ve tried using dotnet-core-uninstall but it only detects dotnet from c:\Program Files which are uninstallable, not the x86 folder.

Would appreciate if you can share how you deleted that dotnet folder

---

<div class="post-metadata">

**Author:** ![AtomR](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AtomR](https://forums.unrealengine.com/u/AtomR)\
**Post date:** [April 21, 2023, 9:46am UTC](https://forums.unrealengine.com/t/system-outofmemoryexception-was-thrown-adding-c-classes-or-generating-visual-studio-project-files-ue-5-1/722613/14 "2023-04-21T09:46:57Z")

</div>

I don’t have a dotnet folder in ProgramFiles so I can’t even try this solution. Anyone know a version of dotnet that for sure works with UE5.1?

[edit]

So the problem is that I only had x86 version of dotnet. Make sure you have the x64 installed and instead of copying and overwriting the dotnet instalation as suggested here, just edit your environmental path variables to have the ProgramFiles dotnet mentioned first and the x86 one mentioned next.

```auto
C:\Program Files\dotnet\
C:\Program Files (x86)\dotnet\

```

As sugested here [Help! I've been trying to create a C++ project in UE5 but every time I create a project it gives me this error message! - #4 by Packetdancer](https://forums.unrealengine.com/t/help-ive-been-trying-to-create-a-c-project-in-ue5-but-every-time-i-create-a-project-it-gives-me-this-error-message/728343/4)
