Skip to content

[src] Use numeric values for the Runtime.Arch field substitution. - #26371

Open
rolfbjarne wants to merge 2 commits into
mainfrom
dev/rolf/enum-values-not-names
Open

[src] Use numeric values for the Runtime.Arch field substitution.#26371
rolfbjarne wants to merge 2 commits into
mainfrom
dev/rolf/enum-values-not-names

Conversation

@rolfbjarne

@rolfbjarne rolfbjarne commented Jul 30, 2026

Copy link
Copy Markdown
Member

ILLink and ILC disagree - incompatibly - about how to specify the substitution value for an enum-typed field in ILLink.Substitutions.xml:

Tool Accepted value Implementation
ILLink the enum member's name ProcessLinkerXmlBase.TryConvertValue hits MetadataType.ValueType, resolves the enum, and matches the value against the enum's field names
ILC the numerical value BodySubstitutionsParser.TryCreateSubstitution switches on type.UnderlyingType.Category (Int32 for an enum), and only int.TryParses the value

So there's no single value that works for both, and each one reports IL2015 for the other's format:

$ dotnet publish
error IL2015: Microsoft.iOS: Invalid value '0' for 'ObjCRuntime.Runtime.Arch'.

$ dotnet publish -p:PublishAot=true
error IL2015: Microsoft.iOS: Invalid value 'DEVICE' for 'ObjCRuntime.Runtime.Arch'.

This surfaced now because on .NET 11 with NativeAOT we skip ILLink entirely and let ILC do all the trimming, so ILC parses our substitution XML itself for the first time.

Fix

Specify both variants for the ObjCRuntime.Runtime.Arch field, in two separate <type> blocks selected by a new ObjCRuntime.IsILCompiler feature switch:

<type fullname="ObjCRuntime.Runtime" feature="ObjCRuntime.IsILCompiler" featurevalue="false" featuredefault="true">
  <field name="Arch" feature="ObjCRuntime.Runtime.Arch.IsSimulator" featurevalue="false" value="DEVICE" />
  <field name="Arch" feature="ObjCRuntime.Runtime.Arch.IsSimulator" featurevalue="true" value="SIMULATOR" />
</type>
<type fullname="ObjCRuntime.Runtime" feature="ObjCRuntime.IsILCompiler" featurevalue="true">
  <field name="Arch" feature="ObjCRuntime.Runtime.Arch.IsSimulator" featurevalue="false" value="0" />
  <field name="Arch" feature="ObjCRuntime.Runtime.Arch.IsSimulator" featurevalue="true" value="1" />
</type>

The feature switch is passed only to ILC, from _XamarinComputeIlcCompileInputs in Xamarin.Shared.Sdk.targets:

<IlcArg Include="--feature:ObjCRuntime.IsILCompiler=true" />

The ILLink variant uses featuredefault="true", so it's the one that applies whenever the feature switch isn't set at all (which is always the case for ILLink).

Validation

tests/dotnet/MySimpleApp/{iOS,tvOS} publish cleanly both with and without -p:PublishAot=true, including the configuration where both ILLink and ILC process the XML.

Reported upstream as dotnet/runtime#131601.

🤖 Pull request description updated by Copilot

Neither ILLink nor ILC understand enum value names in substitution XML: ILLink's
TryConvertValue only switches on primitive MetadataTypes (an enum-typed field
falls through and produces an IL2015 warning), and ILC's TryCreateSubstitution
resolves the enum's underlying type but only parses numeric values.

This went unnoticed until now because ILLink only warned, but on .NET 11 with
NativeAOT we skip ILLink entirely and let ILC do all the trimming - and ILC
turns IL2015 into an error:

    error IL2015: Microsoft.iOS: Invalid value 'DEVICE' for 'ObjCRuntime.Runtime.Arch'.

Use 0 (Arch.DEVICE) and 1 (Arch.SIMULATOR) instead, which also makes the
substitution actually take effect.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: aa4f11db-0d12-4600-bac4-06a7ef562c8a
@rolfbjarne
rolfbjarne requested a review from dalexsoto as a code owner July 30, 2026 16:25
Copilot AI review requested due to automatic review settings July 30, 2026 16:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates ILLink/ILC substitution XML to use numeric values for the ObjCRuntime.Runtime.Arch enum field, ensuring substitutions work correctly with ILC (NativeAOT) where enum names are rejected (IL2015).

Changes:

  • Replace value="DEVICE"/value="SIMULATOR" field substitutions with value="0"/value="1" for Runtime.Arch.
  • Add inline comments documenting why numeric values are required.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/ILLink.Substitutions.iOS.xml Switch Runtime.Arch field substitution values from enum names to numeric constants for ILC compatibility.
src/ILLink.Substitutions.tvOS.xml Same substitution update as iOS to ensure trimming substitutions apply under ILC/NativeAOT.

Comment thread src/ILLink.Substitutions.tvOS.xml Outdated
Comment thread src/ILLink.Substitutions.iOS.xml Outdated
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

… ILLink and ILC want.

The previous commit made the iOS and tvOS tests fail to build, because ILLink
and ILC disagree - incompatibly - about how to specify the substitution value
for an enum-typed field:

* ILLink's ProcessLinkerXmlBase.TryConvertValue hits 'MetadataType.ValueType'
  for an enum, resolves the enum type, and only matches the value against the
  enum's field *names*.
* ILC's BodySubstitutionsParser.TryCreateSubstitution switches on
  'type.UnderlyingType.Category' (Int32 for an enum), and only 'int.TryParse's
  the value.

So there's no single value that works for both, and each one reports IL2015 for
the other's format:

    dotnet publish
    -> error IL2015: Microsoft.iOS: Invalid value '0' for 'ObjCRuntime.Runtime.Arch'.

    dotnet publish -p:PublishAot=true
    -> error IL2015: Microsoft.iOS: Invalid value 'DEVICE' for 'ObjCRuntime.Runtime.Arch'.

Specify both variants, and select between them with a new 'ObjCRuntime.IsILCompiler'
feature switch that we only pass to ILC. The ILLink variant is the default (via
featuredefault="true"), so it's used whenever the feature switch isn't set at all.

Reported upstream as dotnet/runtime#131601.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: aa4f11db-0d12-4600-bac4-06a7ef562c8a
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: b6724ab09526a94f2ddcd979abcedb8b42a77e34 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [CI Build #b6724ab] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 43 tests failed, 160 tests passed.

Failures

❌ dotnettests tests (iOS)

1 tests failed, 0 tests passed.

Failed tests

  • DotNet tests: Failed (Execution failed with exit code 1)
    • Xamarin.Tests.AppIconTest.AlternateAppIcon_Failure(iOS,"ios-arm6...: Failure when comparing error messages:
      Unexpected error message #0:
      Expected: Can't find the AlternateAppIcon 'InexistentAppI...
    • Xamarin.Tests.AppIconTest.AlternateAppIcon(iOS,"ios-arm64"): 'dotnet build' failed with exit code 1
      Full command: /Users/cloudtest/vss/_work/1/s/macios/builds/downloads/dotnet-sdk-10.0.400-...
    • Xamarin.Tests.AppIconTest.AlternateAppIcons(iOS,"ios-arm64"): 'dotnet build' failed with exit code 1
      Full command: /Users/cloudtest/vss/_work/1/s/macios/builds/downloads/dotnet-sdk-10.0.400-...
    • ... and 61 more

Html Report (VSDrops) Download

❌ dotnettests tests (macOS)

1 tests failed, 0 tests passed.

Failed tests

  • DotNet tests: Failed (Execution failed with exit code 1)
    • Xamarin.Tests.ExtensionsTest.AdditionalAppExtensionTest(MacOSX,"...: 'dotnet build' failed with exit code 1
      Full command: /Users/cloudtest/vss/_work/1/s/macios/builds/downloads/dotnet-sdk-10.0.400-...

Html Report (VSDrops) Download

❌ dotnettests tests (tvOS)

1 tests failed, 0 tests passed.

Failed tests

  • DotNet tests: Failed (Execution failed with exit code 1)
    • Xamarin.Tests.AppIconTest.AlternateAppIcon_Failure(TVOS,"tvos-ar...: Failure when comparing error messages:
      Unexpected error message #0:
      Expected: Can't find the AlternateAppIcon 'InexistentAppI...
    • Xamarin.Tests.AppIconTest.AlternateAppIcon(TVOS,"tvos-arm64"): 'dotnet build' failed with exit code 1
      Full command: /Users/cloudtest/vss/_work/1/s/macios/builds/downloads/dotnet-sdk-10.0.400-...
    • Xamarin.Tests.AppIconTest.AlternateAppIcons(TVOS,"tvos-arm64"): 'dotnet build' failed with exit code 1
      Full command: /Users/cloudtest/vss/_work/1/s/macios/builds/downloads/dotnet-sdk-10.0.400-...
    • ... and 29 more

Html Report (VSDrops) Download

❌ monotouch tests (iOS)

19 tests failed, 0 tests passed.

Failed tests

  • monotouch-test/iOS - simulator/Debug: BuildFailure
  • monotouch-test/iOS - simulator/Release (link sdk): BuildFailure
  • monotouch-test/iOS - simulator/Release (link all): BuildFailure
  • monotouch-test/iOS - simulator/Debug (PrepareAssemblies): BuildFailure
  • monotouch-test/iOS - simulator/Debug (PrepareAssemblies, inline dlfcn, dont link): BuildFailure
  • monotouch-test/iOS - simulator/Debug (LinkSdk): BuildFailure
  • monotouch-test/iOS - simulator/Debug (static registrar): BuildFailure
  • monotouch-test/iOS - simulator/Release (all optimizations): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/iOS - simulator/Release (NativeAOT): BuildFailure
  • monotouch-test/iOS - simulator/Release (trimmable static registrar, NativeAOT): BuildFailure
  • monotouch-test/iOS - simulator/Debug (managed static registrar): BuildFailure
  • monotouch-test/iOS - simulator/Release (managed static registrar, all optimizations): BuildFailure
  • monotouch-test/iOS - simulator/Debug (interpreter): BuildFailure
  • monotouch-test/iOS - simulator/Release (interpreter): BuildFailure
  • monotouch-test/iOS - simulator/Release (compat inline Class.GetHandle): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/iOS - simulator/Release (strict inline Class.GetHandle): BuildFailure
  • monotouch-test/iOS - simulator/Release (compat inline dlfcn): BuildFailure
  • monotouch-test/iOS - simulator/Release (strict inline dlfcn, link sdk): BuildFailure
  • monotouch-test/iOS - simulator/Release (NativeAOT, .NET 11 defaults): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))

Html Report (VSDrops) Download

❌ monotouch tests (tvOS)

19 tests failed, 0 tests passed.

Failed tests

  • monotouch-test/tvOS - simulator/Debug: BuildFailure
  • monotouch-test/tvOS - simulator/Release (link sdk): BuildFailure
  • monotouch-test/tvOS - simulator/Release (link all): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (PrepareAssemblies): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (PrepareAssemblies, inline dlfcn, dont link): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (LinkSdk): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Debug (static registrar): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Release (all optimizations): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Release (NativeAOT): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Release (trimmable static registrar, NativeAOT): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Debug (managed static registrar): BuildFailure
  • monotouch-test/tvOS - simulator/Release (managed static registrar, all optimizations): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Debug (interpreter): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Release (interpreter): BuildFailure
  • monotouch-test/tvOS - simulator/Release (compat inline Class.GetHandle): BuildFailure
  • monotouch-test/tvOS - simulator/Release (strict inline Class.GetHandle): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Release (compat inline dlfcn): BuildFailure
  • monotouch-test/tvOS - simulator/Release (strict inline dlfcn, link sdk): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/tvOS - simulator/Release (NativeAOT, .NET 11 defaults): BuildFailure

Html Report (VSDrops) Download

❌ msbuild tests

1 tests failed, 1 tests passed.

Failed tests

  • MSBuild tasks tests: Failed (Execution failed with exit code 1)
    • Xamarin.MacDev.Tasks.DetectSigningIdentityTaskTests.CustomEntitl...: #RunTask-ErrorCount
      : error: No valid iOS code signing keys found in keychain. You need to request a codesigning certificate ...
    • Xamarin.MacDev.Tasks.DetectSigningIdentityTaskTests.EmptyEntitle...: #RunTask-ErrorCount
      : error: No valid iOS code signing keys found in keychain. You need to request a codesigning certificate ...
    • Xamarin.MacDev.Tasks.DetectSigningIdentityTaskTests.EmptyEntitle...: #RunTask-ErrorCount
      : error: No valid iOS code signing keys found in keychain. You need to request a codesigning certificate ...
    • ... and 7 more

Html Report (VSDrops) Download

❌ windows tests

1 tests failed, 2 tests passed.

Failed tests

  • Remote .NET tests/Xamarin.Tests.WindowsTest.BundleStructureWithRemoteMac(iOS,"ios-arm64",All,"Debug"): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.WindowsTest.AssemblyPreparerRemoteTest(iOS,"ios-arm64"): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.WindowsTest.StripTest(iOS,"ios-arm64","Release"): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.DotNetProjectTest.AppWithLibraryWithResourcesReferenceOnRemoteWindows(iOS,"ios-arm64",False): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.PostBuildTest.BuildIpaAndArchiveOnRemoteWindowsTest(iOS,"ios-arm64"): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.DotNetProjectTest.AppWithLibraryWithResourcesReferenceOnRemoteWindows(iOS,"ios-arm64",True): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.WindowsTest.RemoteTest(iOS,"ios-arm64"): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.DotNetProjectTest.BuildProjectsWithExtensionsOnRemoteWindows(iOS,"ios-arm64",False): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.WindowsTest.PluralRuntimeIdentifiersWithRemoteMac(iOS,"ios-arm64","Debug"): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.WindowsTest.PluralRuntimeIdentifiersWithRemoteMac(iOS,"ios-arm64","Release"): Failed: 'dotnet build' failed with exit code 1

Html Report (VSDrops) Download

Successes

✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 19 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: b6724ab09526a94f2ddcd979abcedb8b42a77e34 [PR build]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants