Unable to "Generate Visual Studio Code Project" - How to solve "Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')"

I am trying to execute “Generate Visual Studio Code Project”. Normally I followed the steps from “Setting Up Visual Studio Code for Unreal Engine | Unreal Engine 5.0 Documentation

When I try to execute “Generate Visual Studio Code Project”. I get

Running D:/unreal_engine/UE_5.3/Engine/Build/BatchFiles/Build.bat  -projectfiles -project="<MY_PROJECT>.uproject" -game -rocket -progress
Using bundled DotNet SDK version: 6.0.302
Running UnrealBuildTool: dotnet "..\..\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll" -projectfiles -project="<MY_PROJECT>.uproject" -game -rocket -progress
Log file: <MY_AppDataPATH>\UnrealBuildTool\Log_GPF.txt

Some Platforms were skipped due to invalid SDK setup: IOS, Android, Linux, LinuxArm64.
See the log file for detailed information


Generating VisualStudioCode project files:
Discovering modules, targets and source code for project...
<MY_AppDataPATH>/UnrealEngine/Common/DerivedDataCache: Maintenance finished in +00:00:27.247 and deleted 0 files with total size 0 MiB and 0 empty folders. Scanned 14445 files in 16374 folders with total size 3019 MiB.
Binding IntelliSense data...
Binding IntelliSense data... 100%
Writing project files...
Writing project files... 50%
Unhandled exception: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
   at UnrealBuildTool.VSCodeProjectFileGenerator.WriteWorkspaceIgnoreFile(List`1 Projects) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\VisualStudioCode\VSCodeProjectFileGenerator.cs:line 1552
   at UnrealBuildTool.VSCodeProjectFileGenerator.WritePrimaryProjectFile(ProjectFile UBTProject, PlatformProjectGeneratorCollection PlatformProjectGenerators, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\VisualStudioCode\VSCodeProjectFileGenerator.cs:line 287
   at UnrealBuildTool.ProjectFileGenerator.WriteProjectFiles(PlatformProjectGeneratorCollection PlatformProjectGenerators, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\ProjectFileGenerator.cs:line 3187
   at UnrealBuildTool.ProjectFileGenerator.GenerateProjectFiles(PlatformProjectGeneratorCollection PlatformProjectGenerators, String[] Arguments, Boolean bCacheDataForEditor, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\ProjectFileGenerator.cs:line 1327
   at UnrealBuildTool.GenerateProjectFilesMode.ExecuteAsync(CommandLineArguments Arguments, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Modes\GenerateProjectFilesMode.cs:line 65
   at UnrealBuildTool.UnrealBuildTool.Main(String[] ArgumentsArray) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.cs:line 659

My vscode version is 1.85

Please note that I am able to Generate a project if I select the Visual Studio 2022 IDE.

Can anyone help me with that?

[SOLVED]: I initially started from a Blueprint project which I added C++ support. To solve the issue, I started a new C++ project, then migrated my old asset, then created a visual studio 2022 project then finally I changed my IDE to VisualStudioCode in editor preferences and everthing is now working.

Please note that in the initial project version (Blueprint to C++), apart from my vscode issue, I was receiving .json related errors in regards with Live Coding. Now that I started my project from a C++ based I can now use Live Coding :slight_smile: