Fix TaskParameterTaskItem.ToString() returning type name instead of item-spec - #14095
Merged
JanProvaznik merged 4 commits intoJun 19, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes MSBuild’s marshaled ITaskItem wrapper (TaskParameterTaskItem) so ToString() returns the item-spec (instead of the wrapper’s type name), addressing failures that only surface when task parameters are marshaled (notably under /mt and TaskHost boundaries).
Changes:
- Override
TaskParameterTaskItem.ToString()to return the (escaped) item-spec in both the engine and TaskHost copies ofTaskParameterTaskItem. - Add a regression test covering
ToString()behavior and round-trip serialization forITaskItemtask parameters.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Shared/TaskParameter.cs | Adds TaskParameterTaskItem.ToString() override for the shared (engine) marshaled task-item wrapper. |
| src/MSBuildTaskHost/BackEnd/TaskParameter.cs | Adds the same ToString() override for the TaskHost-side marshaled task-item wrapper. |
| src/Shared/UnitTests/TaskParameter_Tests.cs | Adds a regression test validating ToString() and serialization round-trip behavior. |
JanProvaznik
requested changes
Jun 18, 2026
JanProvaznik
left a comment
Member
There was a problem hiding this comment.
thanks for the find, few things to adjust
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
huulinhnguyen-dev
marked this pull request as ready for review
June 19, 2026 07:38
JanProvaznik
approved these changes
Jun 19, 2026
This was referenced Jun 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix TaskParameterTaskItem.ToString() returning type name instead of item-spec
Fixes #13896
Context
When building xunit with a freshly built MSBuild using the
/mt(multithreaded)flag, the build fails with:
The same build succeeds without
/mt.TaskParameterTaskItemis the internal wrapper MSBuild uses to marshalITaskIteminstances across node/thread boundaries. It did not overrideToString(), so it fell back toobject.ToString()and returned its full .NET type name(
Microsoft.Build.BackEnd.TaskParameter+TaskParameterTaskItem) instead of the item-spec. Every otherITaskItemimplementation (ProjectItemInstance.TaskItem,Utilities.TaskItem,TaskItemData) overridesToString()to return the item-spec.This only surfaces under
/mt: non-thread-safe tasks are routed to a TaskHost for isolation (TaskRouter.NeedsTaskHostInMultiThreadedMode→AssemblyTaskFactory→TaskHostTask), so task outputs come back wrapped asTaskParameterTaskItem(TaskHostTask.cs:641). When a downstream task builds a path viaitem.ToString()— here the third-partyAnnotateReferenceAssembliestask fromTunnelVisionLabs.ReferenceAssemblyAnnotator, used by xunit — it gets the type name instead of the path and fails. Without/mt, the same tasks run in-process viaTaskExecutionHostand receive nativeProjectItemInstance.TaskItemobjects (correctToString()), so the build succeeds.This is a long-standing latent bug; it only became visible now because
/mtmarshals task parameters broadly. Most tasks useitem.ItemSpec, which is always correct, which is why only repos that use a task callingitem.ToString()(like xunit) are affected.Changes Made
ToString()override toTaskParameterTaskIteminsrc/Shared/TaskParameter.cs, returning the escaped item-spec to matchProjectItemInstance.TaskItem.ToString().The reported
/mt(sidecar TaskHost) scenario deserializes items on the engine side using thesrc/Shared/TaskParameter.cscopy, so the fix there fully resolves the issue. The separatesrc/MSBuildTaskHost/BackEnd/TaskParameter.cscopy (the legacy net35/net472 out-of-proc task host) is intentionally left unchanged to keep the scope minimal, per review.Testing
Notes