Skip to content

Reapply "Fix TaskParameterTaskItem serialization perf" #12135

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ccastanedaucf
Copy link
Contributor

Context

Reattempt of #11638

This broke VS tests due to a ToList() not triggering before crossing an AppDomain boundary:

#if FEATURE_APPDOMAIN
if (!AppDomain.CurrentDomain.IsDefaultAppDomain())
{
    metadataToImport = metadataToImport.ToList();
}
#endif

// Fails at runtime
destinationItemAsMetadataContainer.ImportMetadata(metadataToImport);

Error:

   System.Runtime.Serialization.SerializationException : Type 'System.Linq.Enumerable+WhereEnumerableIterator`1[[System.Collections.Generic.KeyValuePair`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutr
al, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' in Assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

Although the above AppDomain check is used in multiple ITaskItem implementations, the out-of-proc TaskHost hits the case where the object was created in the default AppDomain during deserialization, but is copying to an ITaskItem in a separate AppDomain. Therefore, the condition never triggers.

Changes Made

This replaces the check with RemotingServices.IsTransparentProxy(_), which matches how ProjectItemInstance.TaskItem handles this scenario.

Testing

Added UTs for TaskParameterTaskItem.CopyMetadataTo(_) across AppDomains in both directions.

@Copilot Copilot AI review requested due to automatic review settings July 9, 2025 01:33
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR reapplies a previous fix to improve serialization performance of TaskParameterTaskItem across AppDomain boundaries, replacing an AppDomain default check with a transparent proxy check and introducing ITranslatable support.

  • Swapped AppDomain.CurrentDomain.IsDefaultAppDomain() with RemotingServices.IsTransparentProxy() in metadata import
  • Converted TaskParameterTaskItem to implement ITranslatable and updated translation methods
  • Adjusted project references to move IConstrainedEqualityComparer and MSBuildNameIgnoreCaseComparer into the Framework folder

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Utilities/Microsoft.Build.Utilities.csproj Removed duplicated shared comparer references
src/Tasks/Microsoft.Build.Tasks.csproj Removed shared comparer references
src/Shared/UnitTests/TaskParameter_Tests.cs Added AppDomain-crossing unit tests
src/Shared/TaskParameter.cs Refactored translation logic and introduced TaskParameterTaskItem as ITranslatable
src/MSBuildTaskHost/MSBuildTaskHost.csproj Added framework comparers to TaskHost project
src/MSBuild/MSBuild.csproj Removed shared comparer references
src/Framework/MSBuildNameIgnoreCaseComparer.cs Updated comparer to use NativeMethods and EscapeHatches
src/Framework/IConstrainedEqualityComparer.cs Conditional variance for TASKHOST build
src/Build/Microsoft.Build.csproj Removed shared comparer references
Comments suppressed due to low confidence (1)

src/Shared/TaskParameter.cs:294

  • The method references wrappedItems before it is declared. Move the declaration ITaskItem[] wrappedItems = (ITaskItem[])_wrappedParameter; above this line so wrappedItems is in scope when computing length.
            int length = wrappedItems?.Length ?? 0;

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

Successfully merging this pull request may close these issues.

1 participant