{"record":{"id":"3faa7ebb790f8996","repo":"dotnet/wpf","slug":"empty-data-to-load","errorCode":null,"errorMessage":"Empty data to load","messagePattern":"Empty data to load","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs","lineNumber":411,"sourceCode":"        /// the case of Stroke ExtendedPropertyCollection where tag is stored in the stroke descriptor or 0 when tag\n        /// is embeded in the stream\n        /// </summary>\n        /// <param name=\"stream\">Memory buffer to load from</param>\n        /// <param name=\"cbSize\">Maximum length of buffer to read</param>\n        /// <param name=\"guidList\">Guid cache to read from</param>\n        /// <param name=\"tag\">Guid tag to lookup</param>\n        /// <param name=\"guid\">Guid of property</param>\n        /// <param name=\"data\">Data of property</param>\n        /// <returns>Length of buffer read</returns>\n#endif\n        internal static uint DecodeAsISF(Stream stream, uint cbSize, GuidList guidList, KnownTagCache.KnownTagIndex tag, ref Guid guid, out object data)\n        {\n            uint cb, cbRead = 0;\n            uint cbTotal = cbSize;\n\n            if (0 == cbSize)\n            {\n                throw new InvalidOperationException(SR.EmptyDataToLoad);\n            }\n\n            if (0 == tag) // no tag is passed, it must be embedded in the data\n            {\n                uint uiTag;\n                cb = SerializationHelper.Decode(stream, out uiTag);\n                tag = (KnownTagCache.KnownTagIndex)uiTag;\n                if (cb > cbTotal)\n                    throw new ArgumentException(SR.InvalidSizeSpecified, nameof(cbSize));\n\n                cbTotal -= cb;\n                cbRead += cb;\n                System.Diagnostics.Debug.Assert(guid == Guid.Empty);\n                guid = guidList.FindGuid(tag);\n            }\n\n            if (guid == Guid.Empty)\n            {","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs#L393-L429","documentation":"Thrown by CustomAttributeSerializer.DecodeAsISF when asked to decode an ISF custom-attribute payload whose total byte size (cbSize) is zero. There is no attribute data to read, so decoding is impossible. This guards the deserializer against empty or truncated streams.","triggerScenarios":"Calling DecodeAsISF (via ExtendedProperties deserialization, e.g. StrokeCollection Load from ISF) with a zero-length byte array, or passing cbSize=0 for an attribute recovered from a stream.","commonSituations":"Loading ink from a file that was saved empty or truncated; passing a MemoryStream constructed from an empty byte[]; reading an attribute block whose recorded size is 0 due to earlier corruption.","solutions":["Check that the ISF data/byte array is non-empty before attempting Load/DecodeAsISF.","Verify the source file or stream actually contains ink data (length > 0) and was not truncated.","Re-export or re-save the ink data from the original source.","If the empty payload is expected/allowed, skip decoding instead of calling the decoder."],"exampleFix":"// before\nif (attributeData != null) attr = CustomAttributeSerializer.DecodeAsISF(attributeData, 0, stream, ...);\n// after\nif (attributeData != null && attributeData.Length > 0) attr = CustomAttributeSerializer.DecodeAsISF(attributeData, 0, stream, ...);","handlingStrategy":"validation","validationCode":"if (data == null || data.Length == 0) throw new InvalidDataException(\"ISF attribute data is empty; skipping decode\");","typeGuard":"bool HasIsfPayload(byte[] data) => data is { Length: > 0 };","tryCatchPattern":"try { attr = DecodeAsISF(data, 0, stream, size, tag, out guid); }\ncatch (InvalidOperationException) { attr = null; /* empty payload */ }","preventionTips":["Check byte-array length before any ISF decode","Validate saved ink files are non-empty at write time","Handle empty files gracefully in Load paths"],"tags":["ink","isf","deserialization","empty-input"],"backgroundTag":"empty-required-field","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}