Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Unhandled Exception]: Exception of type 'System.OutOfMemoryException' was thrown #11078

Open
ZjzMisaka opened this issue Dec 4, 2024 · 0 comments

Comments

@ZjzMisaka
Copy link

ZjzMisaka commented Dec 4, 2024

Issue Description

When I try to pack my project, an exception was thrown.
Project: https://github.com/ZjzMisaka/PowerThreadPool
Command: dotnet pack PowerThreadPool/PowerThreadPool.csproj -c Release /p:Version=4.14.0

Steps to Reproduce

run dotnet pack PowerThreadPool/PowerThreadPool.csproj -c Release /p:Version=4.14.0 on PowerThreadPool's root path

Actual Behavior

Every time I run the command, the behavior is different.

PS D:\Coding\PowerThreadPool> dotnet pack PowerThreadPool/PowerThreadPool.csproj -c Release /p:Version=4.14.0
Restore complete(0.7)
  PowerThreadPool net6.0 failed, 1 error appeared (0.0)
    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.
          System.TypeInitializationException: The type initializer for 'Microsoft.Build.Collections.CopyOnWritePropertyDictionary`1' threw an exception.
       ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
         at System.Collections.Immutable.ImmutableDictionary.Create[TKey,TValue](IEqualityComparer`1 keyComparer)
         at Microsoft.Build.Collections.CopyOnWritePropertyDictionary`1..cctor()
         --- End of inner exception stack trace ---
         at Microsoft.Build.Execution.ProjectItemDefinitionInstance.Microsoft.Build.Evaluation.IItemDefinition<Microsoft.Build.Execution.ProjectMetadataInstance>.SetMetadata(ProjectMetadataEleme
      nt xml, String evaluatedValue, ProjectMetadataInstance predecessor)
         at Microsoft.Build.Evaluation.Evaluator`4.EvaluateItemDefinitionElement(ProjectItemDefinitionElement itemDefinitionElement)
         at Microsoft.Build.Evaluation.Evaluator`4.EvaluateItemDefinitionGroupElement(ProjectItemDefinitionGroupElement itemDefinitionGroupElement)
         at Microsoft.Build.Evaluation.Evaluator`4.Evaluate()
         at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, Project project, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDiction
      ary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, IDirectoryCacheFactory directoryCacheFactory, ProjectRootElementC
      acheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive)
         at Microsoft.Build.Execution.ProjectInstance.Initialize(ProjectRootElement xml, IDictionary`2 globalProperties, String explicitToolsVersion, String explicitSubToolsetVersion, Int32 visu
      alStudioVersionFromSolution, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionI
      d, Nullable`1 projectLoadSettings, EvaluationContext evaluationContext, IDirectoryCacheFactory directoryCacheFactory)
         at Microsoft.Build.Execution.ProjectInstance..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, BuildParameters buildParameters, ILoggingService loggingServi
      ce, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, Nullable`1 projectLoadSettings)
         at Microsoft.Build.BackEnd.BuildRequestConfiguration.<>c__DisplayClass61_0.<LoadProjectIntoConfiguration>b__0()
         at Microsoft.Build.BackEnd.BuildRequestConfiguration.InitializeProject(BuildParameters buildParameters, Func`1 loadProjectFromFile)
         at Microsoft.Build.BackEnd.RequestBuilder.BuildProject()
         at Microsoft.Build.BackEnd.RequestBuilder.RequestThreadProc(Boolean setThreadParameters)
  PowerThreadPool net5.0                                                                             CoreCompile (0.4s)
  PowerThreadPool net481 failed, 1 error appeared (0.2)
    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.
          System.TypeInitializationException: The type initializer for 'Microsoft.Build.Collections.CopyOnWritePropertyDictionary`1' threw an exception.
       ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
         at System.Collections.Immutable.ImmutableDictionary.Create

OR

PS D:\Coding\PowerThreadPool> dotnet pack PowerThreadPool/PowerThreadPool.csproj -c Release /p:Version=4.14.0
Restore complete(0.8)
  PowerThreadPool net5.0                                                                             CoreCompile (0.5s)
Stack overflow.                                                                                                  (0.6s)

OR

PS D:\Coding\PowerThreadPool> dotnet pack PowerThreadPool/PowerThreadPool.csproj -c Release /p:Version=4.14.0
Restore complete(0.7)
  PowerThreadPool net6.0 failed, 1 error appeared (0.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.
          System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
         at Regex2_TryMatchAtCurrentPosition(RegexRunner, ReadOnlySpan`1)
         at Regex2_Scan(RegexRunner, ReadOnlySpan`1)
         at System.Text.RegularExpressions.Regex.ScanInternal(RegexRunnerMode mode, Boolean reuseMatchObject, String input, Int32 beginning, RegexRunner runner, ReadOnlySpan`1 span, Boolean retu      rnNullIfReuseMatchObject)
         at System.Text.RegularExpressions.Regex.RunAllMatchesWithCallback[TState](String inputString, ReadOnlySpan`1 inputSpan, Int32 startat, TState& state, MatchCallback`1 callback, RegexRunn      erMode mode, Boolean reuseMatchObject)
         at System.Text.RegularExpressions.Regex.RunAllMatchesWithCallback[TState](String input, Int32 startat, TState& state, MatchCallback`1 callback, RegexRunnerMode mode, Boolean reuseMatchO      bject)
         at System.Text.RegularExpressions.Regex.Replace(MatchEvaluator evaluator, Regex regex, String input, Int32 count, Int32 startat)
         at System.Text.RegularExpressions.Regex.Replace(String input, MatchEvaluator evaluator)
         at Microsoft.Build.Evaluation.Expander`2.MetadataExpander.ExpandMetadataLeaveEscaped(String expression, IMetadataTable metadata, ExpanderOptions options, IElementLocation elementLocatio      n, LoggingContext loggingContext)
         at Microsoft.Build.Evaluation.Expander`2.ExpandIntoStringLeaveEscaped(String expression, ExpanderOptions options, IElementLocation elementLocation)
         at Microsoft.Build.BackEnd.TaskBuilder.LogSkippedTask(ItemBucket bucket, TaskExecutionMode howToExecuteTask)
         at Microsoft.Build.BackEnd.TaskBuilder.ExecuteBucket(TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Dictionary`2 lookupHash)
         at Microsoft.Build.BackEnd.TaskBuilder.ExecuteTask(TaskExecutionMode mode, Lookup lookup)
         at Microsoft.Build.BackEnd.TaskBuilder.ExecuteTask(TargetLoggingContext loggingContext, BuildRequestEntry requestEntry, ITargetBuilderCallback targetBuilderCallback, ProjectTargetInstan      ceChild taskInstance, TaskExecutionMode mode, Lookup inferLookup, Lookup executeLookup, CancellationToken cancellationToken)
         at Microsoft.Build.BackEnd.TargetEntry.ProcessBucket(ITaskBuilder taskBuilder, TargetLoggingContext targetLoggingContext, TaskExecutionMode mode, Lookup lookupForInference, Lookup looku      pForExecution)
         at Microsoft.Build.BackEnd.TargetEntry.ExecuteTarget(ITaskBuilder taskBuilder, BuildRequestEntry requestEntry, ProjectLoggingContext projectLoggingCOut of memory.
ontext, CancellationToken cancellatio
      nToken)
         at Microsoft.Build.BackEnd.TargetBuilder.ProcessTargetStack(ITaskBuilder taskBuilder)
         at Microsoft.Build.BackEnd.TargetBuilder.BuildTargets(ProjectLoggingContext loggingContext, BuildRequestEntry entry, IRequestBuilderCallback callback, ValueTuple`2[] targetNames, Lookup       baseLookup, CancellationToken cancellationToken)
         at Microsoft.Build.BackEnd.RequestBuilder.BuildProject()
         at Microsoft.Build.BackEnd.RequestBuilder.RequestThreadProc(Boolean setThreadParameters)
  PowerThreadPool net5.0 failed, 1 error appeared (0.8)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error MSB4018:
      [The "Csc" task failed unexpectedly](https://stackoverflow.com/questions/58525224/the-csc-task-failed-unexpectedly-could-not-load-type-system-valuetuple-3-from)
      System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
         at Microsoft.Build.Utilities.TaskLoggingHelper.LogErrorWithCodeFromResources(String messageResourceName, Object[] messageArgs)
         at Microsoft.CodeAnalysis.BuildTasks.ManagedCompiler.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands, ICompilerServerLogger logger)
         at Microsoft.CodeAnalysis.BuildTasks.ManagedCompiler.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands)
         at Microsoft.Build.Utilities.ToolTask.Execute()
         at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
         at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExec      utionMode howToExecuteTask)
  PowerThreadPool net462 failed, 1 error appeared (0.1)
    C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:
      The "ResolvePackageAssets" task failed unexpectedly.
      System.IO.FileNotFoundException: Could not load file or assembly 'System.Security.Cryptography, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
      File name: 'System.Security.Cryptography, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
         at Microsoft.NET.Build.Tasks.ResolvePackageAssets.HashSettings()
         at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
         at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
         at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
         at Microsoft.NET.Build.Tasks.TaskBase.Execute()
         at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
         at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExec      utionMode howToExecuteTask)
  PowerThreadPool net7.0                                                                       AssignTargetPaths (0.4s)
  PowerThreadPool net461                                                                   ApplyImplicitVersions (0.1s)
  PowerThreadPool net45                                                                     ResolvePackageAssets (0.2s)
  PowerThreadPool net40                                            _CheckForLanguageAndFeatureCombinationSupport (0.1s)
  PowerThreadPool net9.0                                                              ProcessFrameworkReferences (0.1s)
  PowerThreadPool net451                                               CheckForImplicitPackageReferenceOverrides (0.2s)
  PowerThreadPool net47                                                                    ApplyImplicitVersions (0.1s)
  PowerThreadPool net452                                                _CheckForObsoleteDotNetCliToolReferences (0.1s)
  PowerThreadPool net46                                                                 CollectPackageReferences (0.1s)

Analysis

I don't think it was caused by insufficient computer memory, because there was still a lot of free memory at the time.

Versions & Configurations

msbuild:
v17.12.6.51805

OS:
Windows10 22H2

Visual Studio:
Microsoft Visual Studio Community 2022 (64 bit) - Current
version 17.12.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant