Skip to content

Restore InternalsVisibleTo for deprecated MSTest.Engine to fix MethodAccessException (#9769) - #9938

Merged
Evangelink merged 1 commit into
mainfrom
dev/amauryleve/fix-mstest-engine-ivt-methodaccess
Jul 14, 2026
Merged

Restore InternalsVisibleTo for deprecated MSTest.Engine to fix MethodAccessException (#9769)#9938
Evangelink merged 1 commit into
mainfrom
dev/amauryleve/fix-mstest-engine-ivt-methodaccess

Conversation

@Evangelink

Copy link
Copy Markdown
Member

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, with a comment explaining the binary-compatibility rationale. This mirrors the existing TestRequestExecutionTimeInfo compatibility workaround (issue #8925). A single keyed grant re-enables every internal the old engine reaches, not just ArgumentGuard.

Verification

  • Targeted build of Microsoft.Testing.Platform succeeds (0 warnings, 0 errors) across net8.0/net9.0/netstandard2.0.
  • Confirmed the emitted InternalsVisibleTo attributes carry the correct MSFT strong-name public key, matching how the shipped engine is signed, so the keyed grant matches at load time.

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

Copilot AI 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.

Pull request overview

Restores InternalsVisibleTo grants in Microsoft.Testing.Platform to preserve runtime binary compatibility with the already-shipped (deprecated) MSTest.Engine / Microsoft.Testing.Framework assemblies that were compiled when those friend-assembly relationships existed, preventing System.MethodAccessException in Native AOT / source-gen scenarios.

Changes:

  • Re-add InternalsVisibleTo for Microsoft.Testing.Framework (engine assembly name) using the strong-name key.
  • Re-add InternalsVisibleTo for MSTest.Engine using the strong-name key.
  • Document the binary-compatibility rationale inline in the .csproj.
Show a summary per file
File Description
src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj Restores friend-assembly access for deprecated engine assemblies to avoid runtime MethodAccessException with older shipped binaries.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Low

@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.

Note

🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.

Review Summary

This PR restores InternalsVisibleTo grants for the deprecated Microsoft.Testing.Framework and MSTest.Engine assemblies to fix a MethodAccessException when older pre-compiled engine binaries call internal APIs on a newer platform (issue #9769).

Verdict Table

# Dimension Verdict
1 Algorithmic Correctness ✅ N/A — no logic changes
2 Performance ✅ N/A — no runtime impact
3 Thread Safety ✅ N/A
4 Resource Management ✅ N/A
5 Error Handling ✅ N/A
6 Security ✅ OK — grants are to strong-named assemblies with a known key
7 API Design ✅ OK — no new public API surface
8 Backward Compatibility ✅ OK — this is explicitly a backward-compat fix
9 Cross-TFM ✅ N/A
10 Naming & Style ✅ OK — alphabetical order maintained
11 Documentation ✅ OK — thorough inline comment explains rationale and links issue
12 Localization ✅ N/A
13 Testing ✅ N/A — the fix is validated by absence of MethodAccessException at runtime
14 Logging & Diagnostics ✅ N/A
15 IPC & Serialization ✅ N/A
16 Configuration ✅ N/A
17 Build & Packaging ✅ OK
18 Extensibility ✅ N/A
19 Scope Discipline ✅ OK — single-concern PR
20 Code Duplication ✅ N/A
21 Nullability ✅ N/A
22 Disposal ✅ N/A

Summary

Clean PR. The change is minimal, well-documented with an inline comment explaining the binary-compat scenario, references the originating issue (#9769) and the historical PR (#2615), and maintains alphabetical ordering of the InternalsVisibleTo entries. No issues found.

@Evangelink
Evangelink enabled auto-merge (squash) July 14, 2026 15:05
@Evangelink Evangelink added the state/needs-review Awaiting review from the team. label Jul 14, 2026
@Evangelink
Evangelink merged commit c9dc57f into main Jul 14, 2026
29 checks passed
@Evangelink
Evangelink deleted the dev/amauryleve/fix-mstest-engine-ivt-methodaccess 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.

[4.3.0] Native AoT test project fails to compile due to trim analysis errors

3 participants