Skip to content

Commit 23dfb5c

Browse files
[NativeAOT] Reference the designer assembly before rooting it for ILC
ILC only loads assemblies passed to it as references; _Microsoft.Android.Resource.Designer is a compile-time reference but not in @(IlcReference), so rooting it via TrimmerRootAssembly alone fails: ilc error 'Failed to load assembly _Microsoft.Android.Resource.Designer'. Add it to @(IlcReference) too, driven off @(ReferencePath) filtered to the designer so nothing is referenced/rooted when the designer assembly was not generated. @(IlcReference) is ignored by ILLink, so the CoreCLR trimmable path only gets the root. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6d63994 commit 23dfb5c

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.Trimmable.targets

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,27 @@
439439
code path) throws a TypeInitializationException wrapping
440440
System.IO.FileNotFoundException: _Microsoft.Android.Resource.Designer at runtime.
441441
442-
Root the whole _Microsoft.Android.Resource.Designer assembly so it is kept. TrimmerRootAssembly
443-
is honored by both ILLink (CoreCLR) and ILC (NativeAOT). Note that ILC's TrimMode-based rooting
444-
reads @(_IlcManagedInputAssemblies), which _AndroidComputeIlcCompileInputs clears, so
445-
TrimmerRootAssembly is the reliable mechanism here.
442+
Keep the whole _Microsoft.Android.Resource.Designer assembly. Two things are required on the
443+
NativeAOT (ILC) path:
444+
* ILC only loads the assemblies passed to it as references; the designer is a compile-time
445+
reference but is NOT in @(IlcReference), so add it. Rooting an assembly ILC never loaded
446+
fails hard with "Failed to load assembly '_Microsoft.Android.Resource.Designer'".
447+
* Root it so ILC/ILLink keep it whole (TrimMode-based rooting can't be used here because
448+
_AndroidComputeIlcCompileInputs clears @(_IlcManagedInputAssemblies)).
449+
450+
Drive both off @(ReferencePath) filtered to the designer: the item is empty when the designer
451+
assembly was not generated (e.g. no resources / AndroidGenerateResourceDesigner=false), so we
452+
never reference or root a non-existent assembly. @(IlcReference) is ignored by ILLink, so the
453+
CoreCLR path just gets the root.
446454
-->
447455
<Target Name="_RootResourceDesignerForTrimmableTypeMap"
448456
Condition=" '$(AndroidUseDesignerAssembly)' == 'True' and '$(PublishTrimmed)' == 'true' "
449457
BeforeTargets="PrepareForILLink;WriteIlcRspFileForCompilation">
450458
<ItemGroup>
451-
<TrimmerRootAssembly Include="_Microsoft.Android.Resource.Designer" />
459+
<_ResourceDesignerReferenceToRoot Include="@(ReferencePath)"
460+
Condition=" '%(Filename)' == '_Microsoft.Android.Resource.Designer' " />
461+
<IlcReference Include="@(_ResourceDesignerReferenceToRoot->'%(FullPath)')" />
462+
<TrimmerRootAssembly Include="@(_ResourceDesignerReferenceToRoot->'%(Filename)')" />
452463
</ItemGroup>
453464
</Target>
454465
</Project>

0 commit comments

Comments
 (0)