Skip to content

R2R Failed when project contains anonymous types with it's property name with Non-ASCII and same length #135779

Closed

Description

@recumbented

Describe the bug

Since .NET 11 RC2, dotnet publish -p:PublishReadyToRun=true fails when the assembly contains an anonymous type with two or more non-ASCII property names of the same length (e.g. Japanese identifiers).

The same code publishes fine with .NET 10, and also with .NET 11 RC2 when the property names are ASCII.

Steps to reproduce

// Program.cs
var ok = new { x = "", y = "" };   // publishes fine
var ng = new { あ = "", い = "" };  // crossgen2 crashes
Console.WriteLine(ok.Equals(ng));
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net11.0</TargetFramework>
  </PropertyGroup>
</Project>
dotnet publish -c Release -p:PublishReadyToRun=true

Expected behavior

Publish succeeds, as it does with .NET 10 or with ASCII property names.

Actual behavior

C:\Program Files\dotnet\sdk\11.0.100-rc.2.26504.105\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(501,5): error Error: An item with the same key has already been added. Key: DelayLoadHelperImport(DelayLoad_Helper) -> SignaturePointer_GenericLookupSignature(CORINFO_LOOKUP_THISOBJ / TypeHandle: S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<___j__TPar_System___Canon> (R2RCJKBug___f__AnonymousType1_2<System___Canon__System___Canon>__Equals)
    at System.Collections.Generic.Dictionary`2.TryInsert(TKey, TValue, InsertionBehavior) in /_/src/runtime/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs:line 549
    at ILCompiler.ObjectWriter.ObjectWriter.EmitObject(Stream, IReadOnlyCollection`1, IObjectDumper, Logger) in /_/src/runtime/src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs:line 438
    at ILCompiler.DependencyAnalysis.ReadyToRunObjectWriter.EmitReadyToRunObjects(ReadyToRunContainerFormat, Logger) in /_/src/runtime/src/coreclr/tools/aot/ILCompiler.ReadyToRun/CodeGen/ReadyToRunObjectWriter.cs:line 197
    at ILCompiler.ReadyToRunCodegenCompilation.Compile(String) in /_/src/runtime/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs:line 434
    at ILCompiler.Program.RunSingleCompilation(Dictionary`2, InstructionSetSupport, String, Dictionary`2, HashSet`1, ReadyToRunCompilerContext, Logger) in /_/src/runtime/src/coreclr/tools/aot/crossgen2/Program.cs:line 705
    at ILCompiler.Program.Run() in /_/src/runtime/src/coreclr/tools/aot/crossgen2/Program.cs:line 321
    at ILCompiler.Crossgen2RootCommand.<>c__DisplayClass216_0.<.ctor>b__0(ParseResult) in /_/src/runtime/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs:line 275
    at ...
C:\Program Files\dotnet\sdk\11.0.100-rc.2.26504.105\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(501,5): error System.ArgumentException: An item with the same key has already been added. Key: DelayLoadHelperImport(DelayLoad_Helper) -> SignaturePointer_GenericLookupSignature(CORINFO_LOOKUP_THISOBJ / TypeHandle: S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<___j__TPar_System___Canon> (R2RCJKBug___f__AnonymousType1_2<System___Canon__System___Canon>__Equals)
    at System.Collections.Generic.Dictionary`2.TryInsert(TKey, TValue, InsertionBehavior) in /_/src/runtime/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs:line 549
    at ILCompiler.ObjectWriter.ObjectWriter.EmitObject(Stream, IReadOnlyCollection`1, IObjectDumper, Logger) in /_/src/runtime/src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs:line 438
    at ILCompiler.DependencyAnalysis.ReadyToRunObjectWriter.EmitReadyToRunObjects(ReadyToRunContainerFormat, Logger) in /_/src/runtime/src/coreclr/tools/aot/ILCompiler.ReadyToRun/CodeGen/ReadyToRunObjectWriter.cs:line 197
    at ILCompiler.ReadyToRunCodegenCompilation.Compile(String) in /_/src/runtime/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs:line 434
    at ILCompiler.Program.RunSingleCompilation(Dictionary`2, InstructionSetSupport, String, Dictionary`2, HashSet`1, ReadyToRunCompilerContext, Logger) in /_/src/runtime/src/coreclr/tools/aot/crossgen2/Program.cs:line 705
    at ILCompiler.Program.Run() in /_/src/runtime/src/coreclr/tools/aot/crossgen2/Program.cs:line 321
    at ILCompiler.Crossgen2RootCommand.<>c__DisplayClass216_0.<.ctor>b__0(ParseResult) in /_/src/runtime/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs:line 275
    at ...
C:\Program Files\dotnet\sdk\11.0.100-rc.2.26504.105\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(376,5): error NETSDK1096: アセンブリのパフォーマンスの最適化が失敗しました。失敗したアセンブリを最適化の対象から除外するか、PublishReadyToRun プロパティを false に設定してください。

Is this a regression?

Yes. Works with .NET 10 SDK; fails with 11.0.100-rc.2.26504.105.

Are there any workarounds?

  • Rename the anonymous type properties so that their sanitized names don't collide (e.g. use ASCII names), or replace the anonymous type with a named type (record).
  • Exclude the assembly via PublishReadyToRunExclude, or set PublishReadyToRun=false.

dotnet --info output

Host:
  Version:      11.0.0-rc.2.26504.105
  Architecture: x64
  Commit:       820230c386

.NET SDKs installed:
  10.0.402 [C:\Program Files\dotnet\sdk]
  11.0.100-rc.2.26504.105 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 10.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 11.0.0-rc.2.26504.105 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 10.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 11.0.0-rc.2.26504.105 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 10.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 11.0.0-rc.2.26504.105 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

IDE version

JetBrains Rider 2026.2.3.1

Other details

No response

Activity

  1. added
    untriaged
    on Oct 14, 2026
  2. locked and limited conversation to collaborators on Oct 14, 2026
  3. unlocked this conversation on Oct 14, 2026
  4. removed
    untriaged
    on Oct 14, 2026
  5. github-actions commented on Oct 14, 2026

    @github-actions
    Contributor

    🎯 Agentic Issue Triage

    Triage Assessment:

    ➡️ Summary: PublishReadyToRun fails in .NET 11 RC2 with a duplicate-key crossgen2 exception for anonymous types with same-length non-ASCII property names. Consider routing to dotnet/runtime crossgen2 if confirmed.

    Generated by 🏷️ Issue Triage for #135779 · copilot · auto · 19.7 AIC · ⌖ 0.664 AIC · ⊞ 14.3K · ◷

  6. transferred this issue fromdotnet/sdkon Oct 14, 2026
  7. added
    untriaged
    on Oct 14, 2026
  8. removed
    untriaged
    on Oct 14, 2026
  9. jtschuster commented on Oct 14, 2026

    @jtschuster
    Member

    Same root cause as #133229 - non-ascii code mangles to _.

  10. florianwakam commented on Nov 16, 2026

    @florianwakam

    We hit this crash with the official .NET 11 release (SDK 11.0.100), not only with RC2. It happens on an obfuscated third-party library when publishing with -p:PublishReadyToRun=true -p:PublishReadyToRunComposite=true for linux-x64:

    error : Error: An item with the same key has already been added. Key: DelayLoadHelperImport(DelayLoad_Helper) -> SignaturePointer_GenericLookupSignature(CORINFO_LOOKUP_THISOBJ / TypeHandle: S_P_CoreLib_System_Collections_Generic_Dictionary_2<__System___Canon____Syst...
       at ILCompiler.ObjectWriter.ObjectWriter.EmitObject(...) in /_/src/runtime/src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs:line 438
    error NETSDK1096: Optimizing assemblies for performance failed.
    

    The same project publishes fine with .NET 10. The library likely has non-ASCII identifiers of the same length, which matches #133229. Our workaround is to exclude it from ReadyToRun (PublishReadyToRunExclude and PublishReadyToRunCompositeExclusions).

    This now breaks ReadyToRun publishing for anyone who uses an obfuscated dependency on the official .NET 11 release. Could #133230 be considered for an 11.0.x servicing release?

  11. added a commit that references this issue on Nov 17, 2026
    8499fe3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

  • Status
    No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions