Skip to content

Commit 28db7c4

Browse files
[xabt] Use Load() in RunPipeline instead of pre-loading all assemblies
The pre-loading approach in #11208 eagerly loads ALL ResolvedAssemblies into the resolver cache. If any of those assemblies reference netstandard.dll (e.g. netstandard2.1 NuGet packages), Cecil lazy reference resolution will fail with FileNotFoundException since netstandard.dll is not in the search directories. Instead, use resolver.Load(source.ItemSpec) in RunPipeline to load each assembly from its exact path when processed. This ensures the correct TFM version is loaded without eagerly loading all assemblies upfront. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 05d6859 commit 28db7c4

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/Xamarin.Android.Build.Tasks/Tasks/AssemblyModifierPipeline.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,13 @@ public override bool RunTask ()
102102

103103
var resolver = new DirectoryAssemblyResolver (this.CreateTaskLogger (), loadDebugSymbols: ReadSymbols, loadReaderParameters: readerParameters);
104104

105-
// Add SearchDirectories and pre-load ResolvedAssemblies into the resolver cache.
106-
// Pre-loading ensures the correct TFM version is cached before any Cecil lazy
107-
// reference resolution can find wrong-TFM copies from search directories (e.g.,
108-
// a net11.0 copy in a referencing project's output directory).
105+
// Add SearchDirectories for the current architecture's ResolvedAssemblies
109106
foreach (var kvp in perArchAssemblies [sourceArch]) {
110107
ITaskItem assembly = kvp.Value;
111108
var path = Path.GetFullPath (Path.GetDirectoryName (assembly.ItemSpec));
112109
if (!resolver.SearchDirectories.Contains (path)) {
113110
resolver.SearchDirectories.Add (path);
114111
}
115-
if (resolver.Load (assembly.ItemSpec) == null) {
116-
Log.LogDebugMessage ($"Could not pre-load assembly '{assembly.ItemSpec}' into resolver cache.");
117-
}
118112
}
119113

120114
// Set up the FixAbstractMethodsStep and AddKeepAlivesStep
@@ -166,7 +160,14 @@ protected virtual void BuildPipeline (AssemblyPipeline pipeline, MSBuildLinkCont
166160

167161
void RunPipeline (AssemblyPipeline pipeline, ITaskItem source, ITaskItem destination)
168162
{
169-
var assembly = pipeline.Resolver.GetAssembly (source.ItemSpec);
163+
// Use Load with the exact ItemSpec path to ensure the correct TFM version
164+
// is loaded, rather than GetAssembly which strips the path and resolves by
165+
// name through search directories (which may find wrong-TFM copies).
166+
var assembly = pipeline.Resolver.Load (source.ItemSpec);
167+
if (assembly == null) {
168+
Log.LogDebugMessage ($"Could not load assembly '{source.ItemSpec}', skipping.");
169+
return;
170+
}
170171

171172
var context = new StepContext (source, destination) {
172173
CodeGenerationTarget = codeGenerationTarget,

0 commit comments

Comments
 (0)