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

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

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?

3 Likes

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.

10 Likes

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

1 Like

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

2 Likes

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.

Thank you very much! You helped a lot :slight_smile:

1 Like

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

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

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”.

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.

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

1 Like

Thank you!!

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

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.

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