Skip to content

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;

@SimaTian
Copy link
Member

I'm waiting for pipelines to be working, then I will fire up an experimental insertion.
Otherwise we already went through most of the review process in the previous iteration of this change. I will do a final pass after the exp insertion passes.

@YuliiaKovalova
Copy link
Member

@ccastanedaucf please resolve the conflicts

@JanProvaznik
Copy link
Member

JanProvaznik commented Aug 20, 2025

@SimaTian exp insertion is ok, ptal

@SimaTian
Copy link
Member

SimaTian commented Sep 2, 2025

This one is waiting for me. Last week I failed insertion several times - not due to this PR but due to my general struggle with insertion process.
Resolution in progress, I need to babysit one insertion through.

@SimaTian SimaTian self-assigned this Sep 2, 2025
@SimaTian
Copy link
Member

SimaTian commented Sep 5, 2025

Finally a working insertion. LGTM:
https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/667236

@JanProvaznik JanProvaznik merged commit 9ce7e9c into dotnet:main Sep 5, 2025
9 checks passed
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.

4 participants