Preserve invalid friend assembly error#127180
Merged
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @agocke |
…T roundtrip Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/406c2ee2-d0ea-4ba1-a45b-52ac7d68918e Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix FileLoadException when using old library with .NET 10
Preserve invalid friend assembly diagnostics by removing lossy HRESULT roundtrip
Apr 20, 2026
Wrap the friend-assembly name parse failure so the underlying reason (the invalid assembly identity) is kept as the inner exception, while the outer FileLoadException reports which assembly declared the invalid InternalsVisibleTo/friend reference. Update the regression test to assert the outer exception identifies the declaring assembly and the inner exception carries the invalid name and message. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes the CoreCLR friend-assembly parsing error path so that failures while parsing InternalsVisibleTo / IgnoresAccessChecksTo assembly identities preserve the original parsing exception as an inner exception, rather than converting through a lossy HRESULT-only rethrow. It also adds a new loader regression test intended to validate the improved FileLoadException diagnostics for invalid friend assembly names.
Changes:
- Wrap
FriendAssemblyName_t::Init(displayName)in an exception-preservingEX_TRY/EX_CATCH, rethrowing asEEFileLoadExceptionwith the original exception as the inner exception. - Add a new loader regression test project
InvalidFriendAssemblyNamewith an intentionally invalidInternalsVisibleTostring and assertions about the resultingFileLoadExceptionchain.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/assembly.cpp | Preserve underlying assembly-name parse exceptions by wrapping Init failures as inner exceptions when building friend descriptors. |
| src/tests/Loader/classloader/regressions/InvalidFriendAssemblyName/InvalidFriendAssemblyName.csproj | Adds a new regression test project to the loader/classloader regressions suite. |
| src/tests/Loader/classloader/regressions/InvalidFriendAssemblyName/InvalidFriendAssemblyName.cs | Adds a test intended to validate diagnostics for invalid InternalsVisibleTo friend assembly identities. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 1
Address review feedback: clarify that invoking the protected Object.MemberwiseClone drives the accessibility check that parses the invalid InternalsVisibleTo metadata. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mono silently ignores invalid InternalsVisibleTo/friend assembly names rather than throwing, so this diagnostic behavior is CoreCLR-only. Gate the test with CLRTestTargetUnsupported to avoid failing Mono test legs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Open
3 tasks
The test asserts the CoreCLR-specific FileLoadException thrown when parsing an invalid InternalsVisibleTo friend name. The previous CLRTestTargetUnsupported (RuntimeFlavor != coreclr) gate only excluded Mono; NativeAOT test legs run with RuntimeFlavor=coreclr, so the test still ran there and failed because NativeAOT resolves accessibility at compile time and never throws. Use a ConditionalFact that runs only on CoreCLR JIT (not Mono, not NativeAOT). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c29dbe26-1e58-4183-a5f0-28a9fa5fd3ff
EEFileLoadException::Throw asserts its inner exception is not transient. The friend-name parse can fail with a transient exception (e.g. OutOfMemoryException), which would trip that assertion or incorrectly report a transient failure as a load failure. Switch the catch to EX_HOOK and only wrap non-transient exceptions; transient exceptions are rethrown unchanged, matching the pattern in PEAssembly::OpenSystem. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c29dbe26-1e58-4183-a5f0-28a9fa5fd3ff
AaronRobinsonMSFT
approved these changes
Jul 9, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
AaronRobinsonMSFT
approved these changes
Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When an assembly declares an invalid friend reference via
InternalsVisibleTo(for example, specifying both PublicKey and PublicKeyToken), the runtime swallows the assembly name parse failure and throws a generic file load error. This change propagates the invalid assembly name error as an inner exception for the assembly load.cc @dotnet/appmodel @AaronRobinsonMSFT
Before:
After: