Skip to content

[WIP] Fix KeyNotFoundException in ILLink for iOS publish - #123095

Closed
agocke with Copilot wants to merge 1 commit into
mainfrom
copilot/fix-ilink-keynotfound-error
Closed

agocke with Copilot wants to merge 1 commit into
mainfrom
copilot/fix-ilink-keynotfound-error

Conversation

Copilot AI commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original prompt

This section details on the original issue you should resolve

<issue_title>[area-Tools-ILLink]: The given key 'Maui.Health.Services.HealthService/d__17`1' was not present in the dictionary</issue_title>
<issue_description>### Description

When publishing a .NET MAUI iOS app in Release (trimming enabled by default for iOS publish), ILLink crashes with an internal exception (IL1012)

The crash is a KeyNotFoundException for a compiler-generated async state machine type of a generic method:

  • Maui.Health.Services.HealthService/<GetHealthDataAsync>d__12\1`

The problem is in the Maui.Health dependency

Related to:

Reproduction Steps

  1. Create a new .NET MAUI app targeting iOS (net10.0-ios).
  2. Add NuGet package:
    • Kebechet.Maui.Health version 2.0.0 (or any version that contains the same public generic async method shape).
  3. Reference the library in code (just calling the API is enough, example below).
  4. Publish in Release for iOS:

For some reason even local publish worked but it was still crashing in the pipeline

Expected behavior

Pipeline should succeed and the liner should crash on analysis of:
public async partial Task<List<TDto>> GetHealthData<TDto>(HealthTimeRange timeRange, CancellationToken cancellationToken)

and

public async partial Task<bool> WriteHealthData<TDto>(TDto data, CancellationToken cancellationToken) where TDto : HealthMetricBase

Actual behavior

The linker crashes with

/Users/runner/work/SatisFIT/SatisFIT/src/Client/SatisFIT.Client.App/MainPage.xaml(14,30): XamlC warning XC0025: Binding was not compiled because it has an explicitly set Source property and compilation of bindings with Source is not enabled. Consider enabling this optimization by setting the <MauiEnableXamlCBindingWithSourceCompilation>true</MauiEnableXamlCBindingWithSourceCompilation> in your project file and make sure the correct x:DataType is specified for this binding. See https://learn.microsoft.com/dotnet/maui/fundamentals/data-binding/compiled-bindings for more information. [/Users/runner/work/SatisFIT/SatisFIT/src/Client/SatisFIT.Client.App/SatisFIT.Client.App.csproj::TargetFramework=net10.0-ios]
  SatisFIT.Client.App -> /Users/runner/work/SatisFIT/SatisFIT/src/Client/SatisFIT.Client.App/bin/Release/net10.0-ios/ios-arm64/SatisFIT.Client.App.dll
  Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
  Optimizing assemblies for size. This process might take a while.
ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink [/Users/runner/work/SatisFIT/SatisFIT/src/Client/SatisFIT.Client.App/SatisFIT.Client.App.csproj::TargetFramework=net10.0-ios]
  Fatal error in IL Linker
  Unhandled exception. System.Collections.Generic.KeyNotFoundException: The given key 'Maui.Health.Services.HealthService/<WriteHealthData>d__17`1' was not present in the dictionary.
     at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
     at Mono.Linker.Dataflow.CompilerGeneratedState.<GetCompilerGeneratedStateForType>g__MapGeneratedTypeTypeParameters|11_2(TypeDefinition generatedType, Dictionary`2 generatedTypeToTypeArgs, LinkContext context)
     at Mono.Linker.Dataflow.CompilerGeneratedState.<GetCompilerGeneratedStateForType>g__MapGeneratedTypeTypeParameters|11_2(TypeDefinition generatedType, Dictionary`2 generatedTypeToTypeArgs, LinkContext context)
     at Mono.Linker.Dataflow.CompilerGeneratedState.GetCompilerGeneratedStateForType(TypeDefinition type)
     at Mono.Linker.Dataflow.CompilerGeneratedState.GetGeneratedTypeAttributes(TypeDefinition generatedType)
     at ILLink.Shared.TrimAnalysis.FlowAnnotations.GetGeneratedTypeAttributes(TypeDefinition typeDef)
     at ILLink.Shared.TrimAnalysis.FlowAnnotations.BuildTypeAnnotations(TypeDefinition type)
     at ILLink.Shared.TrimAnalysis.FlowAnnotations.GetAnnotations(TypeDefinition type)
     at ILLink.Shared.TrimAnalysis.FlowAnnotations.GetTypeAnnotation(TypeDefinition type)
     at Mono.Linker.Dataflow.DynamicallyAccessedMembersTypeHierarchy.ProcessMarkedTypeForDynamicallyAccessedMembersHierarchy(TypeDefinition type)
     at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, MessageOrigin origin)
     at Mono.Linker.Steps.MarkStep.MarkTypeVisibleToReflection(TypeReference type, DependencyInfo& reason, MessageOrigin& origin)
     at Mono.Linker.Steps.MarkStep.MarkEntireType(TypeDefinition type, DependencyInfo& reason, MessageOrigin origin)
     at Mono.Linker.Steps.MarkStep.MarkEntireType(TypeDefinition type, DependencyInfo& reason, MessageOrigin origin)
     at Mono.Linker.Steps.MarkStep.MarkEntireAssembly(AssemblyDefinition assembly, Mes...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes dotnet/runtime#122800

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

@agocke agocke closed this Jan 12, 2026
Copilot AI requested a review from agocke January 12, 2026 19:12
Copilot stopped work on behalf of agocke due to an error January 12, 2026 19:12
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants