Skip to content

Enable Moq HostTests on ios - #131919

Open
BrzVlad wants to merge 1 commit into
dotnet:mainfrom
BrzVlad:fix-moq-trimming
Open

Enable Moq HostTests on ios#131919
BrzVlad wants to merge 1 commit into
dotnet:mainfrom
BrzVlad:fix-moq-trimming

Conversation

@BrzVlad

@BrzVlad BrzVlad commented Aug 6, 2026

Copy link
Copy Markdown
Member

These use some reflection APIs which were not working on trimming enabled workloads. Expand the trimming descriptor for Moq assembly so the required types are preserved.

Fixes #128405

These use some reflection APIs which were not working on trimming enabled workloads. Expand the trimming descriptor for Moq assembly so the required types are preserved.
Copilot AI review requested due to automatic review settings August 6, 2026 07:11
@dotnet-policy-service dotnet-policy-service Bot added the linkable-framework Issues associated with delivering a linker friendly framework label Aug 6, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-hosting
See info in area-owners.md if you want to be subscribed.

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 re-enables Moq-based HostTests on Apple mobile CoreCLR by ensuring the linker preserves required Moq/Castle types under aggressive trimming, and by removing the platform-specific ActiveIssue skips.

Changes:

  • Added a trimmer root descriptor reference for the shared Castle/Moq linker descriptor in the hosting unit test project.
  • Removed [ActiveIssue(...128405...)] from several Moq/Castle-backed HostTests, keeping the IsReflectionEmitSupported gate.
  • Expanded ILLink.Descriptors.Castle.xml to preserve the Moq.Async namespace during trimming.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Microsoft.Extensions.Hosting.Unit.Tests.csproj Adds the shared Castle/Moq trimmer descriptor to the test project so trimmed workloads keep needed types.
src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs Removes Apple mobile ActiveIssue skips so these Moq-based tests can run again when Reflection.Emit is supported.
eng/testing/ILLinkDescriptors/ILLink.Descriptors.Castle.xml Roots Moq.Async to prevent trimming from removing reflection-activated async-related Moq types.
Suppressed comments (6)

src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs:663

  • Same as above: the comment should match the current gating (Reflection.Emit support + trimmed-workload descriptors) now that these tests are being re-enabled on Apple mobile CoreCLR.
        }

        // Moq heavily utilizes RefEmit, which does not work on most aot workloads
        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
        public async Task WebHostStopAsyncUsesDefaultTimeoutIfNoTokenProvided()
        {

src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs:630

  • Same as above: consider updating this comment to reflect the current reason these tests are guarded (Reflection.Emit support + trimmed-workload descriptors), rather than describing it primarily as an AOT limitation.
        }

        // Moq heavily utilizes RefEmit, which does not work on most aot workloads
        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
        public async Task HostStopAsyncUsesDefaultTimeoutIfGivenTokenDoesNotFire()
        {

src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs:1220

  • Same as above: update this comment to reflect why the tests are conditionally enabled (Reflection.Emit support + trimmed-workload descriptors), to avoid future confusion about Apple mobile support.
        }

        // Moq heavily utilizes RefEmit, which does not work on most aot workloads
        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
        public void Dispose_DisposesAppConfigurationProviders()
        {

src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs:1245

  • Same as above: adjust this comment so it reflects the current reason for the conditional (Reflection.Emit support + trimmed-workload descriptors) rather than primarily calling out AOT.
        }

        // Moq heavily utilizes RefEmit, which does not work on most aot workloads
        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
        public void Dispose_DisposesHostConfigurationProviders()
        {

src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs:1321

  • Same as above: consider updating this comment to align with the current Apple mobile enablement story (Reflection.Emit support + trimmed-workload descriptors).
        }

        // Moq heavily utilizes RefEmit, which does not work on most aot workloads
        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
        public async Task DisposeAsync_DisposesAppConfigurationProviders()
        {

src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs:1346

  • Same as above: now that the ActiveIssue skip is removed, updating this comment helps clarify the intended conditions for these Moq-based tests.
        }

        // Moq heavily utilizes RefEmit, which does not work on most aot workloads
        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
        public async Task DisposeAsync_DisposesHostConfigurationProviders()
        {

@@ -593,7 +593,6 @@ public async Task HostShutsDownWhenTokenTriggers()
}

// Moq heavily utilizes RefEmit, which does not work on most aot workloads
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Extensions-Hosting linkable-framework Issues associated with delivering a linker friendly framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ci-scan] Test failure: HostTests on iossimulator - Castle.DynamicProxy IndexOutOfRangeException

2 participants