dotnet/wpf · error · XamlObjectReaderException
SR.ObjectReaderMultidimensionalArrayNotSupported
Error message
SR.ObjectReaderMultidimensionalArrayNotSupported
What it means
XamlObjectReader throws this when the object graph contains a multidimensional Array (Rank > 1, e.g. int[,]). XAML markup has no syntax for multidimensional arrays, so such values cannot be round-tripped.
Solutions
- Replace multidimensional arrays with jagged arrays (T[][]) which XAML can express
- Use a collection-of-collections or a wrapper type (e.g. Matrix class) instead of T[,]
- Convert the array to a flat array with known row/col dimensions before reading
- Mark the multidimensional array member as not serialized (ignore/visibility attribute)
Example fix
// before
public int[,] Grid { get; set; }
// after
public List<List<int>> Grid { get; set; } Defensive patterns
Strategy: type-guard
Validate before calling
if (value is Array a && a.Rank > 1) throw new InvalidOperationException("Multidimensional arrays are not XAML-round-trippable"); Type guard
bool IsXamlArray(object v) => v is Array a && a.Rank == 1;
Try / catch
try { using var r = new XamlObjectReader(obj); ... } catch (XamlObjectReaderException ex) when (ex.Message.Contains("MultidimensionalArray")) { /* convert to jagged/collection */ } Prevention
- Prefer jagged arrays or collection-of-collections in serializable models
- Wrap matrix data in dedicated types
- Check Rank on all Array members before round-tripping
When it happens
Trigger: new XamlObjectReader(obj) (or XamlServices round-trip) where the graph includes a property or collection value of an array with Rank > 1 (ForArray is invoked via ForArray(Array, SerializerContext)).
Common situations: Numeric/grid data (int[,], double[,]) exposed on serializable classes; image/matrix buffers; porting binary-serialized classes to XAML serialization.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- ' '.' ' is a property without a getter and is not a valid…
- ' '.' ' is a property without a getter and is not a valid…
- ' '.' ' is a property without a getter and is not a valid…
- ' ' is not a valid XAML member name.
- Animation_ChildMustBeKeyFrame
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/5020f7bcc15d2f62.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs:1806
foreach (var ov in propertyInfo.Children)
{
((ObjectOrValueMarkupInfo)ov).EnsureNoDuplicateNames(namesInCurrentScope);
}
}
}
private static string ConvertTypeAndMethodToString(Type type, string methodName, SerializerContext context)
{
string typestring = context.ConvertXamlTypeToString(context.LocalAssemblyAwareGetXamlType(type));
return $"{typestring}.{methodName}";
}
private static ObjectMarkupInfo ForArray(Array value, SerializerContext context)
{
if (value.Rank > 1)
{
throw new XamlObjectReaderException(SR.ObjectReaderMultidimensionalArrayNotSupported);
}
var type = context.LocalAssemblyAwareGetXamlType(value.GetType());
var elementType = type.ItemType;
var items = new MemberMarkupInfo { XamlNode = new XamlNode(XamlNodeType.StartMember, XamlLanguage.Items) };
foreach (object item in value)
{
items.Children.Add(ForObject(item, context));
}
var objectInfo = new ObjectMarkupInfo()
{
XamlNode = new XamlNode(XamlNodeType.StartObject, XamlLanguage.Array),
Object = value,
// Scope = context.ReferenceTable,
Properties =View on GitHub (pinned to 81131a70a4)