{"record":{"id":"fad3036ae570593d","repo":"icsharpcode/ILSpy","slug":"baml-defer-record-points-at-an-offset-that-is-not","errorCode":null,"errorMessage":"BAML defer record points at an offset that is not a record boundary.","messagePattern":"BAML defer record points at an offset that is not a record boundary\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"ICSharpCode.BamlDecompiler/Baml/BamlReader.cs","lineNumber":273,"sourceCode":"\t\t\t\t\tcase BamlRecordType.EndAttributes:\r\n\t\t\t\t\tcase BamlRecordType.DefTag:\r\n\t\t\t\t\tcase BamlRecordType.ClrEvent:\r\n\t\t\t\t\tcase BamlRecordType.Comment:\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tthrow new NotSupportedException();\r\n\t\t\t\t}\r\n\t\t\t\trec.Position = pos;\r\n\r\n\t\t\t\trec.Read(reader);\r\n\t\t\t\tret.Add(rec);\r\n\t\t\t\trecs.Add(pos, rec);\r\n\t\t\t}\r\n\t\t\tfor (int i = 0; i < ret.Count; i++)\r\n\t\t\t{\r\n\t\t\t\tif (ret[i] is IBamlDeferRecord defer)\r\n\t\t\t\t\tdefer.ReadDefer(ret, i, offset => recs.TryGetValue(offset, out var rec)\r\n\t\t\t\t\t\t? rec\r\n\t\t\t\t\t\t: throw new InvalidDataException(\"BAML defer record points at an offset that is not a record boundary.\"));\r\n\t\t\t}\r\n\r\n\t\t\treturn ret;\r\n\t\t}\r\n\t}\r\n}","sourceCodeStart":255,"sourceCodeEnd":279,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.BamlDecompiler/Baml/BamlReader.cs#L255-L279","documentation":"Thrown during the second pass of BamlReader.ReadDocument, when resolving IBamlDeferRecord entries (e.g. DeferableContentStart). A defer record references a stream offset that is not present in the map of record start positions, so the deferred content cannot be linked. InvalidDataException signals corrupt or internally inconsistent BAML.","triggerScenarios":"A DeferableContentStart record (or similar) points at an offset that is mid-record or beyond the stream, so recs.TryGetValue(offset) fails. Caused by corrupted/truncated BAML or a malformed deferable-content section.","commonSituations":"Truncated BAML resource; bit-flipped offset field; BAML assembled by a broken tool.","solutions":["Re-extract the BAML resource from a known-good assembly.","Treat the resource as corrupt and skip it.","Report the failing offset for diagnosis."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    var doc = BamlReader.ReadDocument(stream, token);\n} catch (InvalidDataException ex) when (ex.Message.Contains(\"record boundary\")) {\n    // deferable content references a bad offset; BAML is corrupt\n}","preventionTips":["Do not retry parsing a corrupt stream unchanged; re-obtain the resource."],"tags":["baml","parsing","validation"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}