Skip to content

Fix FileVersionInfo test failure on Apple mobile with trimming#126872

Closed
kotlarmilos wants to merge 1 commit into
dotnet:mainfrom
kotlarmilos:main
Closed

Fix FileVersionInfo test failure on Apple mobile with trimming#126872
kotlarmilos wants to merge 1 commit into
dotnet:mainfrom
kotlarmilos:main

Conversation

@kotlarmilos

Copy link
Copy Markdown
Member

Note

PR description was AI/Copilot-generated.

Summary

Fixes FileVersionInfo_CustomManagedAssembly test failure on Apple mobile (iOS/tvOS) when running with EnableAggressiveTrimming=true.

Problem

The test expected InternalName with .dll extension on iOS, but the actual value was .exe. The field initializer used PlatformDetection.IsWindows to determine the expected extension:

private readonly string OriginalTestAssemblyInternalName = PlatformDetection.IsWindows ?
    "System.Diagnostics.FileVersionInfo.TestAssembly.dll" :
    "System.Diagnostics.FileVersionInfo.TestAssembly.exe";

PlatformDetection.IsWindows chains through RuntimeInformation.IsOSPlatform(OSPlatform.Windows), which appears to be incorrectly evaluated by the IL trimmer during cross-compilation (Windows host → iOS target), causing the field to be initialized with the Windows value (.dll) on iOS.

Fix

Replace PlatformDetection.IsWindows with OperatingSystem.IsWindows(), which is a compile-time constant (#if TARGET_WINDOWS) in the BCL and is immune to trimmer mis-evaluation.

Test Failure

Assert.Equal() Failure: Strings differ
Expected: ···"ystem.Diagnostics.FileVersionInfo.TestAssembly.dll"
Actual:   ···"ystem.Diagnostics.FileVersionInfo.TestAssembly.exe"

Use OperatingSystem.IsWindows() instead of PlatformDetection.IsWindows
for the OriginalTestAssemblyInternalName field initializer. On Apple
mobile CI, EnableAggressiveTrimming=true causes PlatformDetection.IsWindows
(which chains through RuntimeInformation.IsOSPlatform) to be incorrectly
evaluated during cross-compilation trimming. OperatingSystem.IsWindows()
is a compile-time constant in the BCL, immune to trimmer mis-evaluation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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

Fixes a trimming-related test expectation bug for Apple mobile (iOS/tvOS) by avoiding a runtime OS check (PlatformDetection.IsWindows) that can be mis-evaluated during cross-compilation + aggressive trimming, and instead using OperatingSystem.IsWindows() to select the expected internal-name extension.

Changes:

  • Update FileVersionInfo_CustomManagedAssembly expected InternalName/OriginalFilename extension selection to use OperatingSystem.IsWindows().

@kotlarmilos kotlarmilos added the os-ios Apple iOS label Apr 14, 2026
@kotlarmilos kotlarmilos added this to the 11.0.0 milestone Apr 14, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'os-ios': @vitek-karas, @kotlarmilos, @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

@kotlarmilos

Copy link
Copy Markdown
Member Author

/azp run runtime-ioslike

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@kotlarmilos

Copy link
Copy Markdown
Member Author

@jkotas jkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

PlatformDetection.IsWindows chains through RuntimeInformation.IsOSPlatform(OSPlatform.Windows), which appears to be incorrectly evaluated by the IL trimmer during cross-compilation (Windows host → iOS target), causing the field to be initialized with the Windows value (.dll) on iOS.

We should fix the IL trimmer evaluation during cross-compilation instead of this workaround.

@kotlarmilos

Copy link
Copy Markdown
Member Author

Created a tracking issue and closing this PR: #126882

@github-actions github-actions Bot locked and limited conversation to collaborators May 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants