You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.net 9.0.2 aot compilation errror: An item with the same key has already been added. #112629
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)
Reacted by Copilot
Activity
ghost added
untriagedNew issue has not been triaged by the area owner
@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.
@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!
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
Activity
filipnavara commentedon Feb 16, 2025
cc @dotnet/ilc-contrib
[-].net 9.0.2 aot[/-][+].net 9.0.2 aot compilation errror: An item with the same key has already been added.[/+]MichalStrehovsky commentedon Feb 17, 2025
@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.JunZiRuFengJianSuiFeng commentedon Feb 17, 2025
[@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!
MichalStrehovsky commentedon Feb 17, 2025
Can you please paste the stack trace when the exception occurs by following the steps in my previous comment?
JunZiRuFengJianSuiFeng commentedon Feb 17, 2025
@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.Dictionary
2.TryInsert(TKey, TValue, InsertionBehavior) + 0x2ba 1> at ILCompiler.ObjectWriter.ObjectWriter.EmitObject(String, IReadOnlyCollection1, IObjectDumper, Logger) + 0xafb1> 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
MichalStrehovsky commentedon Feb 17, 2025
Yes, thank you!
Fix NativeAOT assembly name mangling collisions (#130012)
Fix NativeAOT assembly name mangling collisions (#130012)