Skip to content

ilc fails with "An item with the same key has already been added. Key: [S.P.CoreLib]System.AppContext.OnFirstChanceException(object)" #110608

Closed as not planned

Description

@rolfbjarne

Description

NativeAOT fails with:

Error: An item with the same key has already been added. Key: [S.P.CoreLib]System.AppContext.OnFirstChanceException(object)
System.ArgumentException: An item with the same key has already been added. Key: [S.P.CoreLib]System.AppContext.OnFirstChanceException(object)
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey, TValue, InsertionBehavior) + 0x310
   at ILCompiler.UnmanagedEntryPointsRootProvider.AddCompilationRoots(IRootingServiceProvider) + 0x1a0
   at ILCompiler.Compilation..ctor(DependencyAnalyzerBase`1, NodeFactory, IEnumerable`1, ILProvider, DebugInformationProvider, IInliningPolicy, Logger) + 0x138
   at ILCompiler.RyuJitCompilationBuilder.ToCompilation() + 0x4a4
   at ILCompiler.Program.Run() + 0x2638
   at ILCompiler.ILCompilerRootCommand.<>c__DisplayClass249_0.<.ctor>b__0(ParseResult) + 0x308

Reproduction Steps

Repro created by passing --make-repro-path ... to ilc:

114180444_MySimpleApp.zip

Expected behavior

ILC should either succeed, or display an actionable error message.

Actual behavior

See above.

Regression?

Yes, this started happening in this maestro bump: dotnet/macios#21570

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. added
    untriaged
    on Dec 11, 2024
  2. dotnet-policy-service commented on Dec 11, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
    See info in area-owners.md if you want to be subscribed.

  3. MichalStrehovsky commented on Dec 11, 2024

    @MichalStrehovsky
    Member

    The targets are hardcoding an implementation detail of the runtime and the implementation detail changed.

    This:

    https://github.com/xamarin/xamarin-macios/blob/3ec925245f5f7f02cf2e465ca9951caf3975f93d/dotnet/targets/Xamarin.Shared.Sdk.targets#L1342

    is now:

    <UnmanagedEntryPointsAssembly Remove="System.Private.CoreLib,HIDDEN" />
    

    (Also please re-add it with ,HIDDEN, I don't know where the re-adding happens, but it's clearly re-added somewhere because the crash is due to this being present as both HIDDEN and not.)

    We don't document this switch, this was added so that Xamarin targets can add stuff to it - I wasn't aware they remove stuff from it.

    The standards for error reporting of incorrect use of undocumented options are pretty low, so I'm going to close this.

  4. removed
    untriaged
    on Dec 11, 2024
  5. rolfbjarne commented on Dec 12, 2024

    @rolfbjarne
    MemberAuthor

    (Also please re-add it with ,HIDDEN, I don't know where the re-adding happens, but it's clearly re-added somewhere because the crash is due to this being present as both HIDDEN and not.)

    The code tries to make sure to not have duplicates by removing System.Private.CoreLib first, then adding back all the assemblies in the next line:

    https://github.com/xamarin/xamarin-macios/blob/3ec925245f5f7f02cf2e465ca9951caf3975f93d/dotnet/targets/Xamarin.Shared.Sdk.targets#L1342-L1343

    I fixed it by instead removing "System.Private.CoreLib" from the list of assemblies to add: dotnet/macios@0f1ef6e

    In any case, thanks for the help.

  6. locked and limited conversation to collaborators on Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions