I am encountering an issue with UIToolkit when using sprites in text in Unity. So far, I haven’t been able to create a minimal reproducible example, as the problem only occurs within a larger scope.
The issue arises in the key rebinding menu when displaying buttons with icons in text using button.text = "<sprite name=...>". In this menu, UIToolkit breaks, starts throwing the following errors, and some images fail to render properly—only the <sprite name=...> tag is displayed instead.
Reproducible in 6000.0.43f1 and 6000.1.0b11.
ArgumentException: An item with the same key has already been added. Key: 1
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <7c8bdf03079d46eabc06e15c1257780a>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <7c8bdf03079d46eabc06e15c1257780a>:0)
UnityEngine.TextCore.Text.SpriteAsset.UpdateLookupTables () (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.SpriteAsset.GetSpriteIndexFromHashcode (System.Int32 hashCode) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.SpriteAsset.SearchForSpriteByHashCode (UnityEngine.TextCore.Text.SpriteAsset spriteAsset, System.Int32 hashCode, System.Boolean includeFallbacks, System.Int32& spriteIndex, UnityEngine.TextCore.Text.TextSettings textSettings) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.TextGenerator.ValidateHtmlTag (UnityEngine.TextCore.Text.TextProcessingElement[] chars, System.Int32 startIndex, System.Int32& endIndex, UnityEngine.TextCore.Text.TextGenerationSettings generationSettings, UnityEngine.TextCore.Text.TextInfo textInfo, System.Boolean& isThreadSuccess) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.TextGenerator.PopulateFontAsset (UnityEngine.TextCore.Text.TextGenerationSettings generationSettings, UnityEngine.TextCore.Text.TextProcessingElement[] textProcessingArray) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.TextGenerator.PrepareFontAsset (UnityEngine.TextCore.Text.TextGenerationSettings generationSettings) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.TextHandle.PrepareFontAsset () (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.UIElements.UITKTextJobSystem+PrepareTextJobData.Execute (System.Int32 index) (at <51d3c247e402427c8c078d62a0e45cb0>:0)
Unity.Jobs.IJobParallelForExtensions+ParallelForJobStruct`1[T].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at <c007129f0c8f49e5b1f7e125061a5718>:0)
ArgumentException: An item with the same key has already been added. Key: -955380455
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <7c8bdf03079d46eabc06e15c1257780a>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <7c8bdf03079d46eabc06e15c1257780a>:0)
UnityEngine.TextCore.Text.SpriteAsset.UpdateLookupTables () (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.SpriteAsset.GetSpriteIndexFromHashcode (System.Int32 hashCode) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.SpriteAsset.SearchForSpriteByHashCode (UnityEngine.TextCore.Text.SpriteAsset spriteAsset, System.Int32 hashCode, System.Boolean includeFallbacks, System.Int32& spriteIndex, UnityEngine.TextCore.Text.TextSettings textSettings) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.TextGenerator.ValidateHtmlTag (UnityEngine.TextCore.Text.TextProcessingElement[] chars, System.Int32 startIndex, System.Int32& endIndex, UnityEngine.TextCore.Text.TextGenerationSettings generationSettings, UnityEngine.TextCore.Text.TextInfo textInfo, System.Boolean& isThreadSuccess) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.TextGenerator.PopulateFontAsset (UnityEngine.TextCore.Text.TextGenerationSettings generationSettings, UnityEngine.TextCore.Text.TextProcessingElement[] textProcessingArray) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.TextGenerator.PrepareFontAsset (UnityEngine.TextCore.Text.TextGenerationSettings generationSettings) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.TextHandle.PrepareFontAsset () (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.UIElements.UITKTextJobSystem+PrepareTextJobData.Execute (System.Int32 index) (at <51d3c247e402427c8c078d62a0e45cb0>:0)
Unity.Jobs.IJobParallelForExtensions+ParallelForJobStruct`1[T].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at <c007129f0c8f49e5b1f7e125061a5718>:0)
IndexOutOfRangeException: Index was outside the bounds of the array.
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <7c8bdf03079d46eabc06e15c1257780a>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <7c8bdf03079d46eabc06e15c1257780a>:0)
UnityEngine.TextCore.Text.SpriteAsset.UpdateLookupTables () (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.SpriteAsset.GetSpriteIndexFromHashcode (System.Int32 hashCode) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.SpriteAsset.SearchForSpriteByHashCode (UnityEngine.TextCore.Text.SpriteAsset spriteAsset, System.Int32 hashCode, System.Boolean includeFallbacks, System.Int32& spriteIndex, UnityEngine.TextCore.Text.TextSettings textSettings) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.TextGenerator.ValidateHtmlTag (UnityEngine.TextCore.Text.TextProcessingElement[] chars, System.Int32 startIndex, System.Int32& endIndex, UnityEngine.TextCore.Text.TextGenerationSettings generationSettings, UnityEngine.TextCore.Text.TextInfo textInfo, System.Boolean& isThreadSuccess) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.TextGenerator.PopulateFontAsset (UnityEngine.TextCore.Text.TextGenerationSettings generationSettings, UnityEngine.TextCore.Text.TextProcessingElement[] textProcessingArray) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.TextGenerator.PrepareFontAsset (UnityEngine.TextCore.Text.TextGenerationSettings generationSettings) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.TextHandle.PrepareFontAsset () (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.UIElements.UITKTextJobSystem+PrepareTextJobData.Execute (System.Int32 index) (at <51d3c247e402427c8c078d62a0e45cb0>:0)
Unity.Jobs.IJobParallelForExtensions+ParallelForJobStruct`1[T].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at <c007129f0c8f49e5b1f7e125061a5718>:0)
Occasionally, after the errors mentioned above occur, the overall text rendering breaks (see video), leading to additional errors listed below.

ArgumentException: The state of the provided MeshGenerationNode is invalid (entry isn't empty).
UnityEngine.UIElements.MeshGenerationContext.Begin (UnityEngine.UIElements.UIR.Entry parentEntry, UnityEngine.UIElements.VisualElement ve) (at <51d3c247e402427c8c078d62a0e45cb0>:0)
UnityEngine.UIElements.UITKTextJobSystem.AddDrawEntries (UnityEngine.UIElements.MeshGenerationContext mgc, System.Object _) (at <51d3c247e402427c8c078d62a0e45cb0>:0)
UnityEngine.UIElements.UIR.MeshGenerationDeferrer.Invoke (UnityEngine.UIElements.UIR.MeshGenerationDeferrer+CallbackInfo ci, UnityEngine.UIElements.MeshGenerationContext mgc) (at <51d3c247e402427c8c078d62a0e45cb0>:0)
UnityEngine.UIElements.UIElementsRuntimeUtilityNative:RepaintPanels(Boolean)
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.TextCore.Text.TextGenerator.ParsingPhase (UnityEngine.TextCore.Text.TextInfo textInfo, UnityEngine.TextCore.Text.TextGenerationSettings generationSettings, System.UInt32& charCode, System.Single& maxVisibleDescender) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.TextGenerator.GenerateTextMesh (UnityEngine.TextCore.Text.TextGenerationSettings generationSettings, UnityEngine.TextCore.Text.TextInfo textInfo) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.TextGenerator.GenerateText (UnityEngine.TextCore.Text.TextGenerationSettings settings, UnityEngine.TextCore.Text.TextInfo textInfo) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.TextCore.Text.TextHandle.UpdateWithHash (System.Int32 hashCode) (at <e493e4ea7412422f9b7eec7c629e14e8>:0)
UnityEngine.UIElements.UITKTextHandle.UpdateMesh () (at <51d3c247e402427c8c078d62a0e45cb0>:0)
UnityEngine.UIElements.UITKTextJobSystem+GenerateTextJobData.Execute (System.Int32 index) (at <51d3c247e402427c8c078d62a0e45cb0>:0)
Unity.Jobs.IJobParallelForExtensions+ParallelForJobStruct`1[T].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at <c007129f0c8f49e5b1f7e125061a5718>:0)


