{"record":{"id":"b3c256ed17ab8c6e","repo":"icsharpcode/ILSpy","slug":"cannot-find-staticresource-position-b3c256","errorCode":null,"errorMessage":"Cannot find StaticResource @{position}","messagePattern":"Cannot find StaticResource @(.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"ICSharpCode.BamlDecompiler/Handlers/Records/StaticResourceIdHandler.cs","lineNumber":42,"sourceCode":"namespace ICSharpCode.BamlDecompiler.Handlers\r\n{\r\n\tclass StaticResourceIdHandler : IHandler\r\n\t{\r\n\t\tpublic BamlRecordType Type => BamlRecordType.StaticResourceId;\r\n\r\n\t\tpublic BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)\r\n\t\t{\r\n\t\t\tvar record = (StaticResourceIdRecord)((BamlRecordNode)node).Record;\r\n\r\n\t\t\tBamlNode found = node;\r\n\t\t\tXamlResourceKey key;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tkey = XamlResourceKey.FindKeyInAncestors(found.Parent, out found);\r\n\t\t\t} while (key != null && record.StaticResourceId >= key.StaticResources.Count);\r\n\r\n\t\t\tif (key == null)\r\n\t\t\t\tthrow new Exception(\"Cannot find StaticResource @\" + node.Record.Position);\r\n\r\n\t\t\tvar resNode = key.StaticResources[record.StaticResourceId];\r\n\r\n\t\t\tvar handler = (IDeferHandler)HandlerMap.LookupHandler(resNode.Type);\r\n\t\t\tvar resElem = handler.TranslateDefer(ctx, resNode, parent);\r\n\r\n\t\t\tparent.Children.Add(resElem);\r\n\t\t\tresElem.Parent = parent;\r\n\r\n\t\t\treturn resElem;\r\n\t\t}\r\n\t}\r\n}\r\n","sourceCodeStart":24,"sourceCodeEnd":56,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.BamlDecompiler/Handlers/Records/StaticResourceIdHandler.cs#L24-L56","documentation":"Thrown by StaticResourceIdHandler.Translate for the same reason as [11] but for a standalone StaticResourceId record: XamlResourceKey.FindKeyInAncestors returns null because no ancestor resource key provides static resources for record.StaticResourceId.","triggerScenarios":"A StaticResourceId record with no enclosing resource key (StaticResourceStart block) among its ancestors that owns the referenced id.","commonSituations":"Malformed/truncated BAML resource references; missing StaticResourceStart.","solutions":["Use the position in the message to find the dangling record.","Re-extract from a clean assembly.","Skip the record and continue."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    handler.Translate(ctx, node, parent);\n} catch (Exception ex) when (ex.Message.StartsWith(\"Cannot find StaticResource\")) {\n    // unresolved StaticResourceId; continue with remaining nodes\n}","preventionTips":["Translate nodes defensively so an unresolved resource reference is reported, not fatal."],"tags":["baml","xaml","static-resource"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}