{"record":{"id":"20432f6c703d6410","repo":"icsharpcode/ILSpy","slug":"cannot-find-staticresource-position","errorCode":null,"errorMessage":"Cannot find StaticResource @{position}","messagePattern":"Cannot find StaticResource @(.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"ICSharpCode.BamlDecompiler/Handlers/Records/PropertyWithStaticResourceIdHandler.cs","lineNumber":54,"sourceCode":"\t\t{\r\n\t\t\tvar record = (PropertyWithStaticResourceIdRecord)((BamlRecordNode)node).Record;\r\n\t\t\tvar doc = new BamlElement(node);\r\n\r\n\t\t\tvar elemAttr = ctx.ResolveProperty(record.AttributeId);\r\n\t\t\tdoc.Xaml = new XElement(elemAttr.ToXName(ctx, null));\r\n\r\n\t\t\tdoc.Xaml.Element.AddAnnotation(elemAttr);\r\n\t\t\tparent.Xaml.Element.Add(doc.Xaml.Element);\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, doc);\r\n\r\n\t\t\tdoc.Children.Add(resElem);\r\n\t\t\tresElem.Parent = doc;\r\n\r\n\t\t\telemAttr.DeclaringType.ResolveNamespace(doc.Xaml, ctx);\r\n\t\t\tdoc.Xaml.Element.Name = elemAttr.ToXName(ctx, null);\r\n\r\n\t\t\treturn doc;\r\n\t\t}\r\n\t}\r\n}","sourceCodeStart":36,"sourceCodeEnd":70,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.BamlDecompiler/Handlers/Records/PropertyWithStaticResourceIdHandler.cs#L36-L70","documentation":"Thrown by PropertyWithStaticResourceIdHandler.Translate when XamlResourceKey.FindKeyInAncestors returns null. The record's StaticResourceId has no enclosing resource key in the ancestor block tree that owns any static resources, so the reference cannot be resolved.","triggerScenarios":"A PropertyWithStaticResourceId record appears with no matching StaticResourceStart/... resource key among its ancestors (or the ancestor key has fewer StaticResources than the id).","commonSituations":"Malformed BAML with a dangling static-resource reference; missing StaticResourceStart block; resource table built out of order.","solutions":["Inspect the record position reported in the message to locate the dangling reference.","Re-extract from a clean assembly.","Report as a malformed resource."],"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    // dangling StaticResourceId; skip this node\n}","preventionTips":["Isolate per-node translation so one bad static-resource reference does not abort the whole document."],"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"}