msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

-mt Concurrency issue

Open SimaTian opened this issue 1 month ago • 1 comments

Issue Description

There is a chance this one has already been resolved (I'm working with the prototype, although rebased onto main). However to not lose the error if that is not the case:

Steps to Reproduce

Run a hot build on the roslyn repository.

Expected Behavior

build works

Actual Behavior

build fails with the reported error message

Analysis

E:\sdk\artifacts\bin\redist\Release\dotnet\sdk\11.0.100-dev\Microsoft.Common.CurrentVersion.targets(2012,5): error MSB4061: The "CombineTargetFrameworkInfoProperties" task could not be instantiated from "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct. E:\sdk\artifacts\bin\redist\Release\dotnet\sdk\11.0.100-dev\Microsoft.Common.CurrentVersion.targets(2012,5): error MSB4060: The "CombineTargetFrameworkInfoProperties" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name. Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler netstandard2.0 failed with 2 error(s) (0.0s) E:\sdk\artifacts\bin\redist\Release\dotnet\sdk\11.0.100-dev\Microsoft.Common.CurrentVersion.targets(2012,5): error MSB4061: The "CombineTargetFrameworkInfoProperties" task could not be instantiated from "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct. E:\sdk\artifacts\bin\redist\Release\dotnet\sdk\11.0.100-dev\Microsoft.Common.CurrentVersion.targets(2012,5): error MSB4060: The "CombineTargetFrameworkInfoProperties" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name. Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost net6.0 succeeded with 1 warning(s) (0.3s)

Versions & Configurations

No response

SimaTian avatar Dec 03 '25 12:12 SimaTian

This one is caused by the private readonly Dictionary<string, int> _taskHostTaskUsage in ProjectTelemetry. There are two "easy" fixes that unfortunately don't work or have other issues:

  • using ConcurrentDictionary causes a regression due to excessive locking.
  • removing the ProjectTelemetry logging solves the performance issue, however it comes at the cost of removing the telemetry we want to have.

TODO: exploration of alternative synchronization options to avoid this issue.

SimaTian avatar Dec 08 '25 12:12 SimaTian

this specific field is not in main, but there is a field introduced by https://github.com/dotnet/msbuild/pull/12623/changes private readonly Dictionary<string, int> _msbuildTaskSubclassUsage = new(); which has this issue and I see in debugger it may be accessed by multiple threads

JanProvaznik avatar Dec 16 '25 17:12 JanProvaznik