Skip to content

[rel/4.3] Restore InternalsVisibleTo for deprecated MSTest.Engine to fix MethodAccessException (#9769) - #9939

Merged
Evangelink merged 1 commit into
rel/4.3from
dev/amauryleve/fix-mstest-engine-ivt-rel43
Jul 14, 2026
Merged

[rel/4.3] Restore InternalsVisibleTo for deprecated MSTest.Engine to fix MethodAccessException (#9769)#9939
Evangelink merged 1 commit into
rel/4.3from
dev/amauryleve/fix-mstest-engine-ivt-rel43

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Backport of #9938 to rel/4.3.

Problem

Native AOT / source-gen test projects fail at runtime with:

System.MethodAccessException: Attempt by method
'Microsoft.Testing.Framework.TestApplicationBuilderExtensions.AddTestFramework(...)'
to access method 'Microsoft.Testing.Platform.Helpers.ArgumentGuard.Ensure(Boolean, String, String)' failed.

Reported in #9769 (comment). Zero tests run, exit code 134.

Root cause

MSTest.Sdk source-gen mode pulls in the (now deprecated) MSTest.Engine package, whose assembly name is still Microsoft.Testing.Framework. That assembly''s TestApplicationBuilderExtensions.AddTestFramework calls the internal Microsoft.Testing.Platform.Helpers.ArgumentGuard.Ensure.

The InternalsVisibleTo grants for Microsoft.Testing.Framework / MSTest.Engine were removed in #2615 when those projects were renamed to Microsoft.Testing.Internal.Framework. The already-shipped engine binary was compiled while the grant existed, so loading it against a newer Microsoft.Testing.Platform that no longer grants the friend relationship throws MethodAccessException.

Fix

Restore the two InternalsVisibleTo grants (Microsoft.Testing.Framework, MSTest.Engine) in Microsoft.Testing.Platform.csproj, mirroring the existing TestRequestExecutionTimeInfo compatibility workaround (issue #8925).

Fixes #9769

…AccessException

The previously shipped MSTest.Engine package (assembly name Microsoft.Testing.Framework) calls internal platform members such as ArgumentGuard.Ensure. The InternalsVisibleTo grants for Microsoft.Testing.Framework / MSTest.Engine were dropped in #2615 during the rename to Microsoft.Testing.Internal.Framework, causing a System.MethodAccessException at runtime when the old engine binary is loaded against the newer platform (see #9769). Restoring the grants keeps binary compatibility, mirroring the TestRequestExecutionTimeInfo workaround.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 32680b56-ae8b-4df9-bf5d-d6be9a1a3dc4

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Generated by Copilot at Evangelink's request — use with caution and always verify.

Review Summary

Verdict: Looks good

This is a straightforward, well-documented backport that restores two InternalsVisibleTo grants to fix a MethodAccessException in shipped binaries.

Positives

  • Excellent inline comment explaining the history and rationale
  • Entries are inserted in alphabetical order, consistent with existing style
  • Minimal, surgical change — no unnecessary modifications
  • Mirrors the established TestRequestExecutionTimeInfo compatibility pattern

No issues found

The change is purely additive (granting friend access to already-shipped assemblies), introduces no new public API surface, and carries no risk of breaking existing behavior. No action items.

@Evangelink Evangelink added the state/needs-review Awaiting review from the team. label Jul 14, 2026
@Evangelink
Evangelink enabled auto-merge (squash) July 14, 2026 15:05
@Evangelink
Evangelink merged commit 3c8bdb9 into rel/4.3 Jul 14, 2026
26 checks passed
@Evangelink
Evangelink deleted the dev/amauryleve/fix-mstest-engine-ivt-rel43 branch July 14, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants