Skip to content

Fix System.MissingMethodException for KeyValuePair Deconstruction #5633

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

Closed
wants to merge 4 commits into from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented May 22, 2025

Overview

This PR addresses an issue where tests fail with a System.MissingMethodException when using MSTest v3.8.3 with .NET 6 projects. The error occurs because tuple deconstruction of KeyValuePair<TKey,TValue> requires the Polyfills.Polyfill.Deconstruct method, which is not available in the netstandard2.0 version of the assembly when used with .NET 6 projects.

Problem

The error occurs in the following scenario:

  • When using MSTest v3.8.3 with .NET 6 projects
  • The netstandard2.0 version of the assembly is being used
  • Code in TestExecutionManager.cs, TestRunCancellationToken.cs, and DeploymentItemUtility.cs uses tuple deconstruction syntax that requires a polyfill implementation

Error message:

System.MissingMethodException: Method not found: 'Void Polyfills.Polyfill.Deconstruct(System.Collections.Generic.KeyValuePair`2<!!0,!!1>, !!0 ByRef, !!1 ByRef)'.

Changes

The changes replace tuple deconstruction pattern with traditional KeyValuePair access:

  1. In TestExecutionManager.cs:

    • Changed foreach ((TestProperty key, object? value) in tcmProperties) to use standard KeyValuePair syntax
    • Changed foreach ((string key, object value) in sourceLevelParameters) to use standard KeyValuePair syntax
  2. In TestRunCancellationToken.cs:

    • Changed the ConcurrentBag collection from ValueTuple to Tuple
    • Updated the foreach loop to access tuple items using .Item1 and .Item2
    • Updated the Register methods to create proper Tuple objects
    • Added missing using directives
  3. In DeploymentItemUtility.cs:

    • Changed foreach ((string? key, string? value) in deploymentItemsData) to use standard KeyValuePair syntax

These changes avoid the need for the Polyfill.Deconstruct method while maintaining the same functionality.

Fixes #5579.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • pkgs.dev.azure.com
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/10.0.0-beta.25229.4.txt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits May 22, 2025 12:26
…yfill

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] System.MissingMethodException: Method not found: 'Void Polyfills.Polyfill.Deconstruct(System.Collections.Generic.KeyValuePair`2<!!0,!!1>, !!0 ByRef, !!1 ByRef)'. Fix System.MissingMethodException for KeyValuePair Deconstruction May 22, 2025
@Copilot Copilot AI requested a review from Youssef1313 May 22, 2025 12:31
Copilot finished work on behalf of Youssef1313 May 22, 2025 12:31
Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Copilot finished work on behalf of Youssef1313 May 22, 2025 12:36
@Youssef1313 Youssef1313 marked this pull request as ready for review May 22, 2025 12:44
@Youssef1313
Copy link
Member

@nohwnd While it's still mysterious why restore isn't behaving as we would expect in the original issue, and we didn't get a binlog from the customer, I think this change is reasonable enough to avoid potential issues.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.05%. Comparing base (b44fb4e) to head (e08f8fd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5633      +/-   ##
==========================================
- Coverage   76.51%   74.05%   -2.46%     
==========================================
  Files         602      602              
  Lines       36561    36560       -1     
==========================================
- Hits        27974    27074     -900     
- Misses       8587     9486     +899     
Flag Coverage Δ
Debug 74.05% <100.00%> (-2.46%) ⬇️
integration 74.05% <100.00%> (-2.46%) ⬇️
production 74.05% <100.00%> (-2.46%) ⬇️
unit 74.05% <100.00%> (-2.47%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...Test.TestAdapter/Execution/TestExecutionManager.cs 82.59% <100.00%> (ø)
...latformServices/Utilities/DeploymentItemUtility.cs 93.61% <100.00%> (ø)

... and 67 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Youssef1313
Copy link
Member

/backport to rel/3.9

Copy link
Contributor

Started backporting to rel/3.9: https://github.com/microsoft/testfx/actions/runs/15195038006

@Youssef1313
Copy link
Member

I think it's too fragile to allow MSTest.TestAdapter netstandard2.0 assembly to be used with MSTest.TestFramework. I'm going to close this PR. The backport was merged already but it doesn't harm as well.

@Youssef1313 Youssef1313 deleted the copilot/fix-5579 branch May 27, 2025 07:26
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.

System.MissingMethodException: Method not found: 'Void Polyfills.Polyfill.Deconstruct(System.Collections.Generic.KeyValuePair`2<!!0,!!1>, !!0 ByRef, !!1 ByRef)'.
3 participants