Restore InternalsVisibleTo for deprecated MSTest.Engine to fix MethodAccessException (#9769) - #9938
Conversation
…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
There was a problem hiding this comment.
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
InternalsVisibleToforMicrosoft.Testing.Framework(engine assembly name) using the strong-name key. - Re-add
InternalsVisibleToforMSTest.Engineusing 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
There was a problem hiding this comment.
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.
Problem
Native AOT / source-gen test projects fail at runtime with:
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'sTestApplicationBuilderExtensions.AddTestFrameworkcalls the internalMicrosoft.Testing.Platform.Helpers.ArgumentGuard.Ensure.The
InternalsVisibleTogrants forMicrosoft.Testing.Framework/MSTest.Enginewere removed in #2615 when those projects were renamed toMicrosoft.Testing.Internal.Framework. The already-shipped engine binary was compiled while the grant existed, so loading it against a newerMicrosoft.Testing.Platformthat no longer grants the friend relationship throwsMethodAccessException.Fix
Restore the two
InternalsVisibleTogrants (Microsoft.Testing.Framework,MSTest.Engine) inMicrosoft.Testing.Platform.csproj, with a comment explaining the binary-compatibility rationale. This mirrors the existingTestRequestExecutionTimeInfocompatibility workaround (issue #8925). A single keyed grant re-enables every internal the old engine reaches, not justArgumentGuard.Verification
Microsoft.Testing.Platformsucceeds (0 warnings, 0 errors) across net8.0/net9.0/netstandard2.0.InternalsVisibleToattributes 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