UE_5.1 Compiling always fail

Whenever I am trying to create new class or even new project, I got this error

The project could not be compiled. Would you like to open it in Visual Studio Code?

Running D:/Program Files/Epic Games/UE_5.1/Engine/Build/BatchFiles/Build.bat Development Win64 -Project="D:/Works/Unreal Projects/EngineTrail/EngineTrail.uproject" -TargetType=Editor -Progress -NoEngineChanges -NoHotReloadFromIDE
Running UnrealBuildTool: dotnet "..\..\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll" Development Win64 -Project="D:/Works/Unreal Projects/EngineTrail/EngineTrail.uproject" -TargetType=Editor -Progress -NoEngineChanges -NoHotReloadFromIDE
Log file: C:\Users\***\AppData\Local\UnrealBuildTool\Log.txt
Creating makefile for EngineTrailEditor (no existing makefile)
@progress push 5%
Parsing headers for EngineTrailEditor
  Running Internal UnrealHeaderTool "D:\xMaro\Works\Unreal Projects\EngineTrail\EngineTrail.uproject" "D:\xMaro\Works\Unreal Projects\EngineTrail\Intermediate\Build\Win64\EngineTrailEditor\Development\EngineTrailEditor.uhtmanifest" -WarningsAsErrors -installed
Total of 12 written
Reflection code generated for EngineTrailEditor in 1.6769257 seconds
@progress pop
Building EngineTrailEditor...
Using Visual Studio 2022 14.29.30148 toolchain (C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.29.30133) and Windows 10.0.22621.0 SDK (C:\Program Files (x86)\Windows Kits\10).
Determining max actions to execute in parallel (12 physical cores, 20 logical cores)
  Executing up to 12 processes, one per physical core
  Requested 1.5 GB free memory per action, 696.28 MB available: limiting max parallel actions to 1
Building 17 actions with 1 process...
ERROR: System.ComponentModel.Win32Exception (998): Invalid access to memory location.
          at EpicGames.Core.ManagedProcessGroup.get_TotalProcessorTime() in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\Shared\EpicGames.Core\ManagedProcess.cs:line 165
          at EpicGames.Core.ManagedProcess.get_TotalProcessorTime() in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\Shared\EpicGames.Core\ManagedProcess.cs:line 1207
          at UnrealBuildTool.ParallelExecutor.RunAction(LinkedAction Action, ManagedProcessGroup ProcessGroup, CancellationToken CancellationToken) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Executors\ParallelExecutor.cs:line 301
          at UnrealBuildTool.ParallelExecutor.ExecuteAction(Task`1[] AntecedentTasks, LinkedAction Action, ManagedProcessGroup ProcessGroup, SemaphoreSlim MaxProcessSemaphore, CancellationToken CancellationToken) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Executors\ParallelExecutor.cs:line 268
[1/17] Resource Default.rc2 cancelled
ERROR: System.ComponentModel.Win32Exception (998): Invalid access to memory location.
          at EpicGames.Core.ManagedProcessGroup.get_TotalProcessorTime() in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\Shared\EpicGames.Core\ManagedProcess.cs:line 165
          at EpicGames.Core.ManagedProcess.get_TotalProcessorTime() in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\Shared\EpicGames.Core\ManagedProcess.cs:line 1207
          at UnrealBuildTool.ParallelExecutor.RunAction(LinkedAction Action, ManagedProcessGroup ProcessGroup, CancellationToken CancellationToken) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Executors\ParallelExecutor.cs:line 301
          at UnrealBuildTool.ParallelExecutor.ExecuteAction(Task`1[] AntecedentTasks, LinkedAction Action, ManagedProcessGroup ProcessGroup, SemaphoreSlim MaxProcessSemaphore, CancellationToken CancellationToken) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Executors\ParallelExecutor.cs:line 268
[2/17] Compile SharedPCH.Engine.ShadowErrors.cpp cancelled
[3/17] Compile EngineTrailGameMode.gen.cpp cancelled
[4/17] Compile EngineTrailProjectile.gen.cpp cancelled
[5/17] Compile TP_WeaponComponent.cpp cancelled
[6/17] Compile EngineTrailProjectile.cpp cancelled
[7/17] Compile TP_WeaponComponent.gen.cpp cancelled
[8/17] Compile TP_PickUpComponent.cpp cancelled
[9/17] Compile TP_PickUpComponent.gen.cpp cancelled
[10/17] Compile EngineTrailCharacter.gen.cpp cancelled
[11/17] Compile EngineTrail.init.gen.cpp cancelled
[12/17] Compile EngineTrailCharacter.cpp cancelled
[13/17] Compile EngineTrailGameMode.cpp cancelled
[14/17] Compile EngineTrail.cpp cancelled
[15/17] Link UnrealEditor-EngineTrail.dll cancelled
[16/17] Link UnrealEditor-EngineTrail.lib cancelled
[17/17] WriteMetadata EngineTrailEditor.target cancelled

I did even removed visual studio, unreal engine and reinstall it but I still get the same error.

I found a solution for this problem, where the problem was with “dotnet” program.

Solutions:
1- If anyone had the same problem just write in the cmd " where.exe dotnet "
if you found that dotnet is exist in two different location just delete the 32bit version
“Program Files(x86)/dotnet” and that will solve the problem.

2-if its not the case just uninstall dotnet and re-download the right addition with is dotnet 6 for unreal engine 5.

That’s all I hope its use full and for more details check this : https://github.com/OmniSharp/omnisharp-vscode/wiki/Troubleshooting:-‘The-.NET-Core-SDK-cannot-be-located.’-errors