From 2e6d980e9d0fbd3aadd6c165b01d807f4f141aeb Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 23 Sep 2026 18:11:56 +0200 Subject: [PATCH 1/5] Add remote Windows trimmer metadata regression coverage Build a Debug iOS app from Windows with a trimmable library and inspect the linked assembly copied back from the Mac. Assert that constructor and method parameter names remain intact, matching the .NET SDK's debugger-friendly trimming behavior. Leave the Windows ILLink target unchanged so CI can demonstrate the regression before the fix. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../TrimmerMetadata/Library/MetadataModel.cs | 20 +++++++++++ .../Library/TrimmerMetadataLibrary.csproj | 9 +++++ tests/dotnet/TrimmerMetadata/iOS/Program.cs | 11 ++++++ .../iOS/TrimmerMetadata.csproj | 19 +++++++++++ tests/dotnet/UnitTests/WindowsTest.cs | 34 +++++++++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 tests/dotnet/TrimmerMetadata/Library/MetadataModel.cs create mode 100644 tests/dotnet/TrimmerMetadata/Library/TrimmerMetadataLibrary.csproj create mode 100644 tests/dotnet/TrimmerMetadata/iOS/Program.cs create mode 100644 tests/dotnet/TrimmerMetadata/iOS/TrimmerMetadata.csproj diff --git a/tests/dotnet/TrimmerMetadata/Library/MetadataModel.cs b/tests/dotnet/TrimmerMetadata/Library/MetadataModel.cs new file mode 100644 index 000000000000..6e3bff2f4470 --- /dev/null +++ b/tests/dotnet/TrimmerMetadata/Library/MetadataModel.cs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace TrimmerMetadataLibrary { + public class MetadataModel { + public int Identifier { get; } + public string Description { get; } + + public MetadataModel (int identifier, string description) + { + Identifier = identifier; + Description = description; + } + + public int WithValue (int value) + { + return Identifier + value; + } + } +} diff --git a/tests/dotnet/TrimmerMetadata/Library/TrimmerMetadataLibrary.csproj b/tests/dotnet/TrimmerMetadata/Library/TrimmerMetadataLibrary.csproj new file mode 100644 index 000000000000..405665e437be --- /dev/null +++ b/tests/dotnet/TrimmerMetadata/Library/TrimmerMetadataLibrary.csproj @@ -0,0 +1,9 @@ + + + + + + net$(BundledNETCoreAppTargetFrameworkVersion) + true + + diff --git a/tests/dotnet/TrimmerMetadata/iOS/Program.cs b/tests/dotnet/TrimmerMetadata/iOS/Program.cs new file mode 100644 index 000000000000..2ad09a7b936f --- /dev/null +++ b/tests/dotnet/TrimmerMetadata/iOS/Program.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Text.Json; + +using TrimmerMetadataLibrary; + +var model = new MetadataModel (1, "description"); +Console.WriteLine (JsonSerializer.Serialize (model)); +Console.WriteLine (model.WithValue (2)); diff --git a/tests/dotnet/TrimmerMetadata/iOS/TrimmerMetadata.csproj b/tests/dotnet/TrimmerMetadata/iOS/TrimmerMetadata.csproj new file mode 100644 index 000000000000..0f4b601771c5 --- /dev/null +++ b/tests/dotnet/TrimmerMetadata/iOS/TrimmerMetadata.csproj @@ -0,0 +1,19 @@ + + + + + + net$(BundledNETCoreAppTargetFrameworkVersion)-ios + Exe + TrimmerMetadata + com.xamarin.trimmermetadata + true + true + + + + + + + + diff --git a/tests/dotnet/UnitTests/WindowsTest.cs b/tests/dotnet/UnitTests/WindowsTest.cs index a0efe53116c8..819ef9b497a9 100644 --- a/tests/dotnet/UnitTests/WindowsTest.cs +++ b/tests/dotnet/UnitTests/WindowsTest.cs @@ -5,6 +5,8 @@ using System.Reflection.Metadata; using System.Reflection.PortableExecutable; +using Mono.Cecil; + #nullable enable namespace Xamarin.Tests { @@ -315,6 +317,38 @@ public void BuildEmbeddedFrameworkInBindingProjectApp (ApplePlatform platform, s DotNet.AssertBuild (project_path, properties, timeout: TimeSpan.FromMinutes (15)); } + [Category ("RemoteWindows")] + [TestCase (ApplePlatform.iOS, "ios-arm64")] + public void TrimmerKeepsParameterNamesWithRemoteMac (ApplePlatform platform, string runtimeIdentifiers) + { + Configuration.IgnoreIfIgnoredPlatform (platform); + Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers); + Configuration.IgnoreIfNotOnWindows (); + + var projectPath = GetProjectPath ("TrimmerMetadata", platform: platform); + Clean (projectPath); + + var properties = GetDefaultProperties (runtimeIdentifiers); + properties ["Configuration"] = "Debug"; + properties ["UseMonoRuntime"] = "false"; + properties ["_CopyLinkerOutputToWindows"] = "true"; + + var result = DotNet.AssertBuild (projectPath, properties, timeout: TimeSpan.FromMinutes (15)); + AssertThatLinkerExecuted (result); + + var assemblyPath = Path.Combine (GetObjDir (projectPath, platform, runtimeIdentifiers), "linked", "TrimmerMetadataLibrary.dll"); + Assert.That (assemblyPath, Does.Exist, "Linked library should be copied back to Windows"); + + using var assembly = AssemblyDefinition.ReadAssembly (assemblyPath); + var model = assembly.MainModule.GetType ("TrimmerMetadataLibrary.MetadataModel"); + Assert.That (model, Is.Not.Null, "Trimmable model should survive linking"); + + var constructor = model!.Methods.Single (method => method.IsConstructor && method.Parameters.Count == 2); + var withValue = model.Methods.Single (method => method.Name == "WithValue"); + Assert.That (constructor.Parameters.Select (parameter => parameter.Name), Is.EqualTo (new [] { "identifier", "description" }), "Constructor parameter names"); + Assert.That (withValue.Parameters.Select (parameter => parameter.Name), Is.EqualTo (new [] { "value" }), "Method parameter name"); + } + static void AssertWarningsEqual (IList expected, IList actual, string message) { if (expected.Count == actual.Count) { From f994b0c5c452f86cbc4e283889cd0bcf1ddfd252 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 23 Sep 2026 18:24:58 +0200 Subject: [PATCH 2/5] Disambiguate Cecil assembly reader in Windows test WindowsTest already imports System.Reflection.Metadata, which also defines AssemblyDefinition. Qualify the Cecil type used to inspect the linked fixture assembly so the regression test compiles without changing either existing namespace import. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- tests/dotnet/UnitTests/WindowsTest.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/dotnet/UnitTests/WindowsTest.cs b/tests/dotnet/UnitTests/WindowsTest.cs index 819ef9b497a9..4c948dd61c04 100644 --- a/tests/dotnet/UnitTests/WindowsTest.cs +++ b/tests/dotnet/UnitTests/WindowsTest.cs @@ -5,8 +5,6 @@ using System.Reflection.Metadata; using System.Reflection.PortableExecutable; -using Mono.Cecil; - #nullable enable namespace Xamarin.Tests { @@ -339,7 +337,7 @@ public void TrimmerKeepsParameterNamesWithRemoteMac (ApplePlatform platform, str var assemblyPath = Path.Combine (GetObjDir (projectPath, platform, runtimeIdentifiers), "linked", "TrimmerMetadataLibrary.dll"); Assert.That (assemblyPath, Does.Exist, "Linked library should be copied back to Windows"); - using var assembly = AssemblyDefinition.ReadAssembly (assemblyPath); + using var assembly = Mono.Cecil.AssemblyDefinition.ReadAssembly (assemblyPath); var model = assembly.MainModule.GetType ("TrimmerMetadataLibrary.MetadataModel"); Assert.That (model, Is.Not.Null, "Trimmable model should survive linking"); From bf87a61ec8aacbec057249dec4fc2f7dacf9ae71 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 23 Sep 2026 19:06:21 +0200 Subject: [PATCH 3/5] Avoid null-forgiving access in metadata regression Handle a missing linked model explicitly so the test reports its assertion failure before inspecting methods. This also keeps the remote regression test aligned with the repository's nullable code conventions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- tests/dotnet/UnitTests/WindowsTest.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/dotnet/UnitTests/WindowsTest.cs b/tests/dotnet/UnitTests/WindowsTest.cs index 4c948dd61c04..2ad3a2a2d276 100644 --- a/tests/dotnet/UnitTests/WindowsTest.cs +++ b/tests/dotnet/UnitTests/WindowsTest.cs @@ -339,9 +339,12 @@ public void TrimmerKeepsParameterNamesWithRemoteMac (ApplePlatform platform, str using var assembly = Mono.Cecil.AssemblyDefinition.ReadAssembly (assemblyPath); var model = assembly.MainModule.GetType ("TrimmerMetadataLibrary.MetadataModel"); - Assert.That (model, Is.Not.Null, "Trimmable model should survive linking"); + if (model is null) { + Assert.Fail ("Trimmable model should survive linking"); + return; + } - var constructor = model!.Methods.Single (method => method.IsConstructor && method.Parameters.Count == 2); + var constructor = model.Methods.Single (method => method.IsConstructor && method.Parameters.Count == 2); var withValue = model.Methods.Single (method => method.Name == "WithValue"); Assert.That (constructor.Parameters.Select (parameter => parameter.Name), Is.EqualTo (new [] { "identifier", "description" }), "Constructor parameter names"); Assert.That (withValue.Parameters.Select (parameter => parameter.Name), Is.EqualTo (new [] { "value" }), "Method parameter name"); From 2dd3da40d3d5b0173e761526fc044d0a39f08911 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 23 Sep 2026 19:09:12 +0200 Subject: [PATCH 4/5] Keep metadata fixture free of trim-unsafe JSON calls The regression inspects linked parameter names directly, so the app only needs to root its constructor and method. Avoid reflection-based JSON serialization warnings that could fail the remote build before the intended metadata assertion runs. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- tests/dotnet/TrimmerMetadata/iOS/Program.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/dotnet/TrimmerMetadata/iOS/Program.cs b/tests/dotnet/TrimmerMetadata/iOS/Program.cs index 2ad09a7b936f..910cdd15d661 100644 --- a/tests/dotnet/TrimmerMetadata/iOS/Program.cs +++ b/tests/dotnet/TrimmerMetadata/iOS/Program.cs @@ -2,10 +2,9 @@ // Licensed under the MIT License. using System; -using System.Text.Json; using TrimmerMetadataLibrary; var model = new MetadataModel (1, "description"); -Console.WriteLine (JsonSerializer.Serialize (model)); +Console.WriteLine (model.Description); Console.WriteLine (model.WithValue (2)); From 84f3445295f5f5d011e0c5619276047cc168273e Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 24 Sep 2026 09:09:01 +0200 Subject: [PATCH 5/5] Preserve linker metadata in remote Windows iOS builds Forward the SDK's KeepMetadata items and PreserveSymbolPaths setting to the remote ILLink task. Debug builds now retain parameter names in trimmed assemblies when driven from Windows, matching builds driven directly from the Mac; deterministic source path handling also stays consistent with the SDK target. The previously committed Pair-to-Mac regression test observed the missing constructor names on Windows CI before this fix. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Common.After.targets | 2 ++ 1 file changed, 2 insertions(+) diff --git a/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Common.After.targets b/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Common.After.targets index 8fa867cf8f57..e3b56aeccc1c 100644 --- a/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Common.After.targets +++ b/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Common.After.targets @@ -397,6 +397,7 @@ Copyright (C) 2011-2013 Xamarin. All rights reserved. TrimMode="$(TrimMode)" DefaultAction="$(_TrimmerDefaultAction)" RemoveSymbols="$(TrimmerRemoveSymbols)" + PreserveSymbolPaths="$(_TrimmerPreserveSymbolPaths)" FeatureSettings="@(_TrimmerFeatureSettings)" CustomData="@(_TrimmerCustomData)" @@ -406,6 +407,7 @@ Copyright (C) 2011-2013 Xamarin. All rights reserved. UnusedInterfaces="$(_TrimmerUnusedInterfaces)" IPConstProp="$(_TrimmerIPConstProp)" Sealer="$(_TrimmerSealer)" + KeepMetadata="@(_TrimmerKeepMetadata)" Warn="$(ILLinkWarningLevel)" NoWarn="$(NoWarn)"