{"record":{"id":"773d0d68338b8128","repo":"dotnet/wpf","slug":"sr-integercollectionlengthlessthanzero","errorCode":null,"errorMessage":"SR.IntegerCollectionLengthLessThanZero","messagePattern":"SR\\.IntegerCollectionLengthLessThanZero","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlInt32CollectionSerializer.cs","lineNumber":275,"sourceCode":"            BinaryReader reader)\n        {\n            return DeserializeFrom( reader ); \n        }          \n\n\n        private static Int32Collection DeserializeFrom( BinaryReader reader )\n        {\n            Int32Collection theCollection; \n            IntegerCollectionType type; \n\n            type = (IntegerCollectionType) reader.ReadByte(); \n\n            int count = reader.ReadInt32(); \n\n\n            if ( count < 0 ) \n            {\n                throw new ArgumentException(SR.IntegerCollectionLengthLessThanZero); \n            }                \n                    \n            theCollection = new Int32Collection( count ); \n                                \n            if ( type == IntegerCollectionType.Consecutive ) \n            {\n                // Get the first integer \n                int first = reader.ReadInt32(); \n\n                for( int i = 0; i < count; i ++)\n                {\n                    theCollection.Add( first + i ); \n                }\n            }\n            else\n            {\n                switch( type ) \n                {","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlInt32CollectionSerializer.cs#L257-L293","documentation":"During binary XAML deserialization (BAML) of an IntegerCollection, DeserializeFrom reads an Int32 length prefix from the stream. If the length is negative the serialized data is corrupt or was produced by an incompatible writer, so ArgumentException(SR.IntegerCollectionLengthLessThanZero) is thrown before allocating the Int32Collection.","triggerScenarios":"Calling ConvertCustomBinaryToObject or StaticConvertCustomBinaryToObject on a BAML stream whose IntegerCollection record begins with a negative Int32 count (e.g. truncated, corrupted, or hand-crafted binary data).","commonSituations":"Corrupted or truncated compiled BAML resources in an assembly, binary data edited or generated by third-party tooling, or version mismatches where the binary XAML format changed between WPF builds.","solutions":["Rebuild the application so BAML resources are regenerated from valid XAML source.","Verify the binary stream being passed to ConvertCustomBinaryToObject is intact and originates from a matching WPF compiler version.","Regenerate the resource containing the Int32Collection (e.g. recompile the .xaml into the assembly)."],"exampleFix":"// before: deserializing a possibly corrupted stream\nvar obj = XamlInt32CollectionSerializer.StaticConvertCustomBinaryToObject(syncVersion, suspectBytes);\n// after: guard length prefix first\nif (BitConverter.ToInt32(suspectBytes, 0) < 0) throw new InvalidDataException(\"Corrupt IntegerCollection binary data\");\nvar obj = XamlInt32CollectionSerializer.StaticConvertCustomBinaryToObject(syncVersion, suspectBytes);","handlingStrategy":"validation","validationCode":"if (data == null || data.Length < 4 || BitConverter.ToInt32(data, 0) < 0)\n    throw new InvalidDataException(\"IntegerCollection binary payload has invalid length prefix\");","typeGuard":null,"tryCatchPattern":"try { obj = serializer.ConvertCustomBinaryToObject(data); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"less than zero\")) { /* treat as corrupt payload */ }","preventionTips":["Never hand-edit compiled BAML; always regenerate from XAML source.","Validate binary resource integrity (size/hash) before deserialization."],"tags":["wpf","baml","deserialization","argument-exception"],"backgroundTag":"invalid-argument-value","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"}