icsharpcode/ILSpy · error · Exception
Cannot find StaticResource @{position}
Error message
Cannot find StaticResource @{position} What it means
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.
Source
Thrown at ICSharpCode.BamlDecompiler/Handlers/Records/StaticResourceIdHandler.cs:42
namespace ICSharpCode.BamlDecompiler.Handlers
{
class StaticResourceIdHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.StaticResourceId;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
{
var record = (StaticResourceIdRecord)((BamlRecordNode)node).Record;
BamlNode found = node;
XamlResourceKey key;
do
{
key = XamlResourceKey.FindKeyInAncestors(found.Parent, out found);
} while (key != null && record.StaticResourceId >= key.StaticResources.Count);
if (key == null)
throw new Exception("Cannot find StaticResource @" + node.Record.Position);
var resNode = key.StaticResources[record.StaticResourceId];
var handler = (IDeferHandler)HandlerMap.LookupHandler(resNode.Type);
var resElem = handler.TranslateDefer(ctx, resNode, parent);
parent.Children.Add(resElem);
resElem.Parent = parent;
return resElem;
}
}
}
View on GitHub (pinned to 60c08fcb74)
Solutions
- Use the position in the message to find the dangling record.
- Re-extract from a clean assembly.
- Skip the record and continue.
Defensive patterns
Strategy: try-catch
Try / catch
try {
handler.Translate(ctx, node, parent);
} catch (Exception ex) when (ex.Message.StartsWith("Cannot find StaticResource")) {
// unresolved StaticResourceId; continue with remaining nodes
} Prevention
- Translate nodes defensively so an unresolved resource reference is reported, not fatal.
When it happens
Trigger: A StaticResourceId record with no enclosing resource key (StaticResourceStart block) among its ancestors that owns the referenced id.
Common situations: Malformed/truncated BAML resource references; missing StaticResourceStart.
Related errors
AI-assisted analysis of icsharpcode/ILSpy@60c08fcb74 (2026-08-13).
Data as JSON: /api/errors/b3c256ed17ab8c6e.
Report an issue: GitHub.