Skip to content

Preserve invalid friend assembly diagnostics by removing lossy HRESULT roundtrip#127180

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-fileloadexception-net10
Draft

Preserve invalid friend assembly diagnostics by removing lossy HRESULT roundtrip#127180
Copilot wants to merge 2 commits intomainfrom
copilot/fix-fileloadexception-net10

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 20, 2026

This addresses a misleading FileLoadException path triggered by invalid InternalsVisibleTo metadata (e.g., specifying both PublicKey and PublicKeyToken). Instead of surfacing a generic load failure, the runtime now preserves the underlying assembly-name parse failure details.

  • ## Description
    • CoreCLR error-path change
      • In FriendAssemblyDescriptor::CreateFriendAssemblyDescriptor (src/coreclr/vm/assembly.cpp), switched from InitNoThrow + THROW_HR_ERROR_WITH_INFO(...) to throwing Init(...) directly.
      • This avoids the HRESULT-based rethrow that dropped the original diagnostic context and produced a confusing file-load error.
    • Regression coverage
      • Added Loader/classloader/regressions/InvalidFriendAssemblyName test project.
      • New test uses an intentionally invalid InternalsVisibleTo string and asserts the thrown FileLoadException carries the invalid assembly identity and a message indicating invalid assembly name.
// Before
hr = pFriendAssemblyName->InitNoThrow(displayName);
if (SUCCEEDED(hr))
{
    hr = pFriendAssemblyName->CheckFriendAssemblyName();
}
if (FAILED(hr))
{
    THROW_HR_ERROR_WITH_INFO(hr, pAssembly);
}

// After
pFriendAssemblyName->Init(displayName);
hr = pFriendAssemblyName->CheckFriendAssemblyName();

@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

…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 requested review from Copilot and removed request for Copilot April 20, 2026 21:49
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
Copilot AI requested a review from elinor-fung April 20, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Weird FileLoadException when using old library and .NET 10

2 participants