{"record":{"id":"fb3d0238e8fe2352","repo":"stride3d/stride","slug":"spritename","errorCode":null,"errorMessage":"spriteName","messagePattern":"spriteName","errorType":"exception","errorClass":"KeyNotFoundException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/SpriteSheet.cs","lineNumber":43,"sourceCode":"        /// <summary>\n        /// Find the index of a sprite in the group using its name.\n        /// </summary>\n        /// <param name=\"spriteName\">The name of the sprite</param>\n        /// <returns>The index value</returns>\n        /// <remarks>If two sprites have the provided name then the first sprite found is returned</remarks>\n        /// <exception cref=\"KeyNotFoundException\">No sprite in the group have the given name</exception>\n        public int FindImageIndex(string spriteName)\n        {\n            if (Sprites != null)\n            {\n                for (int i = 0; i < Sprites.Count; i++)\n                {\n                    if (Sprites[i].Name == spriteName)\n                        return i;\n                }\n            }\n\n            throw new KeyNotFoundException(spriteName);\n        }\n\n        /// <summary>\n        /// Gets or sets the image of the group at <paramref name=\"index\"/>.\n        /// </summary>\n        /// <param name=\"index\">The image index</param>\n        /// <returns>The image</returns>\n        public Sprite this[int index]\n        {\n            get { return Sprites[index]; }\n            set { Sprites[index] = value; }\n        }\n\n        /// <summary>\n        /// Gets or sets the image of the group having the provided <paramref name=\"name\"/>.\n        /// </summary>\n        /// <param name=\"name\">The name of the image</param>\n        /// <returns>The image</returns>","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/SpriteSheet.cs#L25-L61","documentation":"SpriteSheet.FindImageIndex throws KeyNotFoundException wrapping the requested spriteName when no Sprite in the sheet has that Name. The exception message is the missing name itself. It is thrown by the FindImageIndex helper used by the SpriteSheet constructor and Create factory methods, so a bad name aborts sheet creation/lookup.","triggerScenarios":"Passing a sprite name to SpriteSheet.FindImageIndex (directly or via SpriteSheet.Create/constructor) that does not match any Sprites[i].Name exactly — case-sensitive full-match comparison.","commonSituations":"Typo or wrong casing in the sprite name string; sprite removed or renamed in the image atlas but the code still references the old name; querying a different sheet than intended; localized/auto-generated sprite names changing between asset rebuilds.","solutions":["Verify the exact sprite name (case-sensitive) against the sprites defined in the SpriteSheet asset","Iterate sheet.Sprites and log available Names to find the correct one","Use an index-based lookup or resolve the name once and cache the index","Add a Contains/name check before calling FindImageIndex if the name is user-supplied"],"exampleFix":"// before\nint idx = spriteSheet.FindImageIndex(\"player_idle\");\n// after\nint idx = spriteSheet.FindImageIndex(\"PlayerIdle\"); // exact name from the sheet asset\n// or defensively:\nint idx = spriteSheet.Sprites.FindIndex(s => s.Name == name);\nif (idx < 0) { /* handle missing sprite */ }","handlingStrategy":"try-catch","validationCode":"int idx = spriteSheet.Sprites.FindIndex(s => s.Name == spriteName);\nif (idx < 0) throw new InvalidOperationException($\"Sprite '{spriteName}' not in sheet; available: {string.Join(\",\", spriteSheet.Sprites.Select(s => s.Name))}\");","typeGuard":"static bool HasSprite(SpriteSheet sheet, string name) => sheet?.Sprites?.Any(s => s.Name == name) == true;","tryCatchPattern":"try { idx = spriteSheet.FindImageIndex(name); }\ncatch (KeyNotFoundException e) { Log.Warning($\"Sprite '{e.Message}' missing from sheet\"); idx = fallbackIndex; }","preventionTips":["Copy sprite names directly from the SpriteSheet asset — they are case-sensitive","Add a unit test that resolves all sprite names used in code","Log the sheet's sprite names at startup in debug builds"],"tags":["csharp","sprite","key-not-found","asset-lookup"],"backgroundTag":"resource-not-found","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}