Skip to content

[Java.Interop.Tools.Cecil] Fix retry logic in ReadAssembly to skip symbol loading#1401

Merged
jonathanpeppers merged 1 commit intomainfrom
dev/peppers/loadDebugSymbols
Apr 14, 2026
Merged

[Java.Interop.Tools.Cecil] Fix retry logic in ReadAssembly to skip symbol loading#1401
jonathanpeppers merged 1 commit intomainfrom
dev/peppers/loadDebugSymbols

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

@jonathanpeppers jonathanpeppers commented Apr 13, 2026

Summary

The retry path in DirectoryAssemblyResolver.ReadAssembly was broken - it set reader_parameters.ReadSymbols = false but LoadFromMemoryMappedFile checked the instance field loadDebugSymbols instead, so the retry would re-open the same locked PDB file and throw the same IOException.

Problem

When a PDB file in the NuGet cache is locked by another process (e.g. the .NET SDK trimmer running concurrently), LoadSymbols throws an IOException. The ReadAssembly method has a catch block that is supposed to retry without symbols, but the retry calls LoadFromMemoryMappedFile which checks loadDebugSymbols (always true) and calls LoadSymbols again - hitting the same locked file.

This causes error XAPTP7000 / XA0009 build failures:

error XAPTP7000: error XA0009: Error while loading assembly: 'Xamarin.AndroidX.Core.dll'.
   ---> System.IO.IOException: The process cannot access the file 'Xamarin.AndroidX.Core.pdb'
        because it is being used by another process.

Fix

Add an explicit bool loadSymbols parameter to LoadFromMemoryMappedFile so the retry can pass false to actually skip symbol loading.

Context: dotnet/android#11081

Copilot AI review requested due to automatic review settings April 13, 2026 20:08
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes DirectoryAssemblyResolver.ReadAssembly() retry behavior in Java.Interop.Tools.Cecil so that when the initial read fails due to locked PDB/symbol loading, the retry actually skips symbol loading instead of re-attempting the same failing path (addressing build failures like XA0009/XAPTP7000 reported in dotnet/android#11081).

Changes:

  • Thread a new bool loadSymbols parameter through LoadFromMemoryMappedFile() to explicitly control whether symbols are loaded.
  • Update the retry path in ReadAssembly() to call LoadFromMemoryMappedFile(..., loadSymbols: false) after a failure when loading with symbols.

@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/loadDebugSymbols branch 2 times, most recently from 366a73b to c23b860 Compare April 13, 2026 20:40
Copy link
Copy Markdown
Member Author

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

🤖 AI Review Summary

Verdict: ✅ LGTM (pending CI)

Found 0 issues, 1 suggestion:

  • 💡 Testing: Consider adding a regression test for the locked-PDB retry path (DirectoryAssemblyResolverTests.cs)

Analysis

The bug is real and well-explained: LoadFromMemoryMappedFile checked the instance field loadDebugSymbols instead of respecting the caller's intent, so the retry path in ReadAssembly re-opened the same locked PDB and threw the same IOException.

The fix correctly threads a bool loadSymbols parameter through LoadFromMemoryMappedFile so the retry can pass false to actually skip symbol loading. The if (!loadDebugSymbols) throw; guard is a nice defensive addition — if we're not loading symbols in the first place, there's nothing to retry.

👍 Clean, minimal fix that addresses root cause rather than symptoms. Good PR description with clear problem/fix separation.

⚠️ CI note: The Azure DevOps dotnet.java-interop pipeline is still queued. LGTM is conditional on CI passing.


Review generated by android-reviewer from review guidelines.

…mbol loading

The retry in ReadAssembly sets reader_parameters.ReadSymbols = false,
but LoadFromMemoryMappedFile checks the instance field loadDebugSymbols
instead, so the retry re-opens the same locked PDB file and throws
the same IOException.

Fix by passing an explicit loadSymbols parameter to
LoadFromMemoryMappedFile so the retry can actually skip symbol loading.

When loadDebugSymbols is false, rethrow immediately since there is
nothing to retry.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/loadDebugSymbols branch from c23b860 to 8bd8268 Compare April 13, 2026 20:46
@jonathanpeppers jonathanpeppers merged commit 85919bb into main Apr 14, 2026
2 checks passed
@jonathanpeppers jonathanpeppers deleted the dev/peppers/loadDebugSymbols branch April 14, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants