The first parameter of
Array.CreateInstance expects the element type of the array. You pass the entire property type, which is, as you have just found out by checking
property.PropertyType.IsArray, an array type (specifically,
Bar – i.e. an array of
To get the element type of an array type, use its
var array = Array.CreateInstance(property.PropertyType.GetElementType(), 0);
I suppose you will replace the zero passed to the second argument with a higher number when required, unless you actually want only empty arrays.