dotnet/wpf · error
SR.UnknownIndexType
Error message
SR.UnknownIndexType
What it means
The IntegerCollection BAML record encodes an IntegerCollectionType describing how values follow the count in the stream. DeserializeFrom switches on that type; an unrecognized type value means the binary payload does not conform to the known format, so ArgumentException(SR.UnknownIndexType) is thrown. This code path is compiled only under PBTCOMPILER.
Solutions
- Recompile the XAML/BAML with the same WPF version the runtime uses.
- Inspect the binary payload's type byte and confirm it is a supported IntegerCollectionType.
- If handling untrusted input, pre-validate the type byte before deserialization and reject unknown values.
Defensive patterns
Strategy: validation
Validate before calling
byte typeByte = data[4]; // after Int32 count
if (!Enum.IsDefined(typeof(IntegerCollectionType), typeByte))
throw new InvalidDataException($"Unknown IntegerCollectionType {typeByte}"); Try / catch
try { obj = serializer.ConvertCustomBinaryToObject(data); }
catch (ArgumentException ex) { LogCorruptBaml(ex); return null; } Prevention
- Compile and consume BAML with the same WPF/framework version.
- Treat untrusted binary XAML as untrusted input and pre-validate type bytes.
When it happens
Trigger: ConvertCustomBinaryToObject / StaticConvertCustomBinaryToObject encounters an IntegerCollection whose IntegerCollectionType byte is not one of the supported enum values (e.g. data produced by a newer/older compiler).
Common situations: Cross-version BAML incompatibility, hand-modified compiled resources, fuzzed or adversarial binary input to a XAML deserializer.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- SR.IntegerCollectionLengthLessThanZero
- Unrecognized float type in BAML file.
- Can't Assign to Known Type attributes
- Could not find prefix for type
- Drawing Attribute tag embedded in ISF stream does not match…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/6aee9db94137aea0.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlInt32CollectionSerializer.cs:324
{
theCollection.Add( (int) reader.ReadUInt16());
}
}
break;
case IntegerCollectionType.Integer :
{
for ( int i = 0; i < count; i++ )
{
int value = reader.ReadInt32();
theCollection.Add( value);
}
}
break;
default:
throw new ArgumentException(SR.UnknownIndexType);
}
}
return theCollection;
}
#endif
#endregion Conversions
internal enum IntegerCollectionType : byte
{
Unknown = 0,
Consecutive = 1,
Byte = 2,
UShort= 3,
Integer= 4
}
}View on GitHub (pinned to 81131a70a4)