dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.24k stars 1.35k forks source link

[Unhandled Exception]: The paging file is too small for this operation to complete. #10784

Closed TomBecker-BD closed 1 month ago

TomBecker-BD commented 1 month ago

Issue Description

Building a Visual Studio solution with mixed C++ and C# projects.

First build failure: Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=4.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The paging file is too small for this operation to complete. (Exception from HRESULT: 0x800705AF)

Followed by four identical This is an unhandled exception in MSBuild failures with the same message and stack trace.

Steps to Reproduce

  1. Edited some C++ code in Visual Studio.
  2. Started a "Build Solution"
  3. The C++ library project built. Looks like it was okay.
  4. The first C# project failed: Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=4.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The paging file is too small for this operation to complete. (Exception from HRESULT: 0x800705AF)
  5. The next four C# projects failed with This is an unhandled exception in MSBuild. The error message and stack trace look the same for all four failures.

I am not expecting to be able to reproduce this issue. I restarted the PC and was able to build successfully.

Actual Behavior

Build started at 4:33 PM...
1>------ Build started: Project: Asdf.Native, Configuration: Release x64 ------
1>NativeAsdf.cpp
1>   Creating library C:\bd\src\Asdf\Asdf.Native\Output\Asdf.Native.lib and object C:\bd\src\Asdf\Asdf.Native\Output\Asdf.Native.exp
1>Generating code
1>16 of 787 functions ( 2.0%) were compiled, the rest were copied from previous compilation.
1>  13 functions were new in current compilation
1>  0 functions had inline decision re-evaluated but remain unchanged
1>Finished generating code
1>Asdf.Native.vcxproj -> C:\bd\src\Asdf\Asdf.Native\Output\Asdf.Native.dll
2>------ Build started: Project: Asdf, Configuration: Debug x64 ------
2>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :
2>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(85,5): error : Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=4.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The paging file is too small for this operation to complete. (Exception from HRESULT: 0x800705AF)
2>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.MainCore(String[] args)
2>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(String[] args)
2>Done building project "Asdf.csproj" -- FAILED.
3>------ Build started: Project: Asdf.Test, Configuration: Debug x64 ------
4>------ Build started: Project: Ghjk.Test, Configuration: Debug x64 ------
5>------ Build started: Project: Zxcv.Test, Configuration: Debug x64 ------
6>------ Build started: Project: Tyui.Specflow.Test, Configuration: Debug x64 ------
6>SpecFlowFeatureFiles: Features\Tyui.feature;Features\Qwer.feature
3>MSBUILD : error : This is an unhandled exception in MSBuild -- PLEASE UPVOTE AN EXISTING ISSUE OR FILE A NEW ONE AT https://aka.ms/msbuild/unhandled
3>MSBUILD : error :     System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
3>MSBUILD : error :    at Go2(RegexRunner )
3>MSBUILD : error :    at System.Text.RegularExpressions.RegexRunner.Scan(Regex regex, String text, Int32 textbeg, Int32 textend, Int32 textstart, Int32 prevlen, Boolean quick, TimeSpan timeout)
3>MSBUILD : error :    at System.Text.RegularExpressions.Regex.Run(Boolean quick, Int32 prevlen, String input, Int32 beginning, Int32 length, Int32 startat)
3>MSBUILD : error :    at System.Text.RegularExpressions.Regex.Match(String input, Int32 startat)
3>MSBUILD : error :    at System.Text.RegularExpressions.RegexReplacement.Replace(MatchEvaluator evaluator, Regex regex, String input, Int32 count, Int32 startat)
3>MSBUILD : error :    at System.Text.RegularExpressions.Regex.Replace(String input, MatchEvaluator evaluator)
3>MSBUILD : error :    at Microsoft.Build.Evaluation.Expander`2.MetadataExpander.ExpandMetadataLeaveEscaped(String expression, IMetadataTable metadata, ExpanderOptions options, IElementLocation elementLocation, LoggingContext loggingContext)
3>MSBUILD : error :    at Microsoft.Build.Evaluation.Expander`2.ExpandIntoStringLeaveEscaped(String expression, ExpanderOptions options, IElementLocation elementLocation)
3>MSBUILD : error :    at Microsoft.Build.BackEnd.TaskBuilder.LogSkippedTask(ItemBucket bucket, TaskExecutionMode howToExecuteTask)
3>MSBUILD : error :    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteBucket>d__19.MoveNext()
3>MSBUILD : error : --- End of stack trace from previous location where exception was thrown ---
3>MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
3>MSBUILD : error :    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteTask>d__18.MoveNext()
3>MSBUILD : error : --- End of stack trace from previous location where exception was thrown ---
3>MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
3>MSBUILD : error :    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
3>MSBUILD : error :    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteTask>d__13.MoveNext()
3>MSBUILD : error : --- End of stack trace from previous location where exception was thrown ---
3>MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
3>MSBUILD : error :    at Microsoft.Build.BackEnd.TargetEntry.<ProcessBucket>d__51.MoveNext()
3>MSBUILD : error : --- End of stack trace from previous location where exception was thrown ---
3>MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
3>MSBUILD : error :    at Microsoft.Build.BackEnd.TargetEntry.<ExecuteTarget>d__44.MoveNext()
3>MSBUILD : error : --- End of stack trace from previous location where exception was thrown ---
3>MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
3>MSBUILD : error :    at Microsoft.Build.BackEnd.TargetBuilder.<ProcessTargetStack>d__23.MoveNext()
3>MSBUILD : error : --- End of stack trace from previous location where exception was thrown ---
3>MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
3>MSBUILD : error :    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
3>MSBUILD : error :    at Microsoft.Build.BackEnd.TargetBuilder.<BuildTargets>d__10.MoveNext()
3>MSBUILD : error : --- End of stack trace from previous location where exception was thrown ---
3>MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
3>MSBUILD : error :    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
3>MSBUILD : error :    at Microsoft.Build.BackEnd.RequestBuilder.<BuildProject>d__67.MoveNext()
3>MSBUILD : error : --- End of stack trace from previous location where exception was thrown ---
3>MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
3>MSBUILD : error :    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
3>MSBUILD : error :    at Microsoft.Build.BackEnd.RequestBuilder.<RequestThreadProc>d__58.MoveNext()
3>Done building project "Asdf.Test.csproj" -- FAILED.

Analysis

No response

Versions & Configurations

Microsoft Visual Studio Enterprise 2022 (64-bit) - Current Version 17.11.4

MSBuild version 17.11.9+a69bbaaf5 for .NET Framework 17.11.9.46202

maridematte commented 1 month ago

Hello, thank you for filling the issue regarding your build as the message indicates. This failure seems to be related to the OutOfMemoryException, which means your system might not have enough memory to run the build. Could you check that: 1) Your system was doing any memory heavy processing task at the same time as the build? 2) Can you reproduce this with nothing else running on your machine?

TomBecker-BD commented 1 month ago
  1. The system where this happened has 32 GB of RAM. The paging file is 36864 MB. I probably had Outlook, Teams, VS Code, and one tab in Chrome open at the time, not actively doing anything in any of them. No heavy processing except for running MSBuild.
  2. I don't expect to be able to reproduce the problem. It seems like a rare glitch. MSBuild asked me to file an issue, so I did.

The original exception was: "Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=4.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The paging file is too small for this operation to complete. (Exception from HRESULT: 0x800705AF)".

The System.OutOfMemoryException came later.

maridematte commented 1 month ago

MSBuild doesn't handle System.OutOfMemoryException very well, and it ends up throwing other unrelated exception depending on where it ran out of memory.

We do appreciate bug and issue reports, and make an effort to look into all of them. If you do not expect to run into this issue again, I will close this issue. If you happen to run into it again, please feel free to reopen it and we can work together to collect more information on it.