Skip to content

.net 9.0.2 aot compilation errror: An item with the same key has already been added. #112629

Closed

Description

@JunZiRuFengJianSuiFeng

This is an AOT-related error. I'm getting the following error when compiling to AOT:

Tip 1:
""C:\Users\Administrator.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\9.0.2\tools\ilc" @"obj\Release\net9.0\win-x86\native\MyApp.ilc.rsp"" has exited with code 1

Tip 2:
"An item with the same key has already been added. Key: _________________________________"

However, my project compiles fine without AOT enabled.

Code Replication:
Since the error doesn't point to a specific line of code, I can't give a specific block of code. If required, I can provide the complete project.

My solution:
After I changed the name of the class in the code, it was able to compile successfully.

Opinion:
I think it's a bug in the AOT compiler handling the character set, which causes a symbol conflict during the conversion.

Environment:
SDK version: .NET 9.0.2
Development Environment: VS2022(17.13.0)

Activity

  1. ghost added
    untriaged
    on Feb 15, 2025
  2. filipnavara commented on Feb 16, 2025

    @filipnavara
    Member

    cc @dotnet/ilc-contrib

  3. transferred this issue fromdotnet/sdkon Feb 17, 2025
  4. changed the title [-].net 9.0.2 aot[/-] [+].net 9.0.2 aot compilation errror: An item with the same key has already been added.[/+] on Feb 17, 2025
  5. MichalStrehovsky commented on Feb 17, 2025

    @MichalStrehovsky
    Member

    @JunZiRuFengJianSuiFeng could you open a command prompt, change the directory to where is your project file, and re-run the failing command ("C:\Users\Administrator\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\9.0.2\tools\ilc" @"obj\Release\net9.0\win-x86\native\MyApp.ilc.rsp"). It should print a stack when it crashes - please paste it here.

  6. added
    needs-author-action
    on Feb 17, 2025
  7. JunZiRuFengJianSuiFeng commented on Feb 17, 2025

    @JunZiRuFengJianSuiFeng
    Author

    @JunZiRuFengJianSuiFeng could you open a command prompt, change the directory to where is your project file, and re-run the failing command (). It should print a stack when it crashes - please paste it here."C:\Users\Administrator\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\9.0.2\tools\ilc" @"obj\Release\net9.0\win-x86\native\MyApp.ilc.rsp"

    [@MichalStrehovsky]
    I've tested out the cause of the specific error:
    The reason is that my C# code is encoded with non-English identifiers, which is correct at managed compilation, but the AOT compiler will underscore non-English identifiers to '_', so this error occurs, I hope this feedback will help you improve the AOT functionality!

  8. removed
    needs-author-action
    on Feb 17, 2025
  9. MichalStrehovsky commented on Feb 17, 2025

    @MichalStrehovsky
    Member

    Can you please paste the stack trace when the exception occurs by following the steps in my previous comment?

  10. added
    needs-author-action
    on Feb 17, 2025
  11. JunZiRuFengJianSuiFeng commented on Feb 17, 2025

    @JunZiRuFengJianSuiFeng
    Author

    Can you please paste the stack trace when the exception occurs by following the steps in my previous comment?

    @MichalStrehovsky
    Don't know if you're referring to this:
    1>EXEC(0,0): Error: An item with the same key has already been added. Key: _________________________________
    1>System.ArgumentException: An item with the same key has already been added. Key: _________________________________
    1> at System.Collections.Generic.Dictionary2.TryInsert(TKey, TValue, InsertionBehavior) + 0x2ba 1> at ILCompiler.ObjectWriter.ObjectWriter.EmitObject(String, IReadOnlyCollection1, IObjectDumper, Logger) + 0xafb
    1> at ILCompiler.ObjectWriter.ObjectWriter.EmitObject(String, IReadOnlyCollection`1, NodeFactory, ObjectWritingOptions, IObjectDumper, Logger) + 0x142
    1> at ILCompiler.RyuJitCompilation.CompileInternal(String, ObjectDumper) + 0xbb
    1> at ILCompiler.Compilation.ILCompiler.ICompilation.Compile(String, ObjectDumper) + 0x5d
    1> at ILCompiler.Program.Run() + 0x2c4c
    1> at ILCompiler.ILCompilerRootCommand.<>c__DisplayClass240_0.<.ctor>b__0(ParseResult) + 0x321

  12. removed
    needs-author-action
    on Feb 17, 2025
  13. MichalStrehovsky commented on Feb 17, 2025

    @MichalStrehovsky
    Member

    Yes, thank you!

  14. added this to the Future milestone on Mar 13, 2025
  15. removed
    untriaged
    on Mar 13, 2025
  16. added a commit that references this issue on Jul 13, 2026
    b0657b0
  17. added a commit that references this issue on Jul 15, 2026
    a54deac
  18. locked and limited conversation to collaborators on Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

  • Status
    No status

Relationships

None yet

Development

No branches or pull requests

Issue actions