diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs index 01b71be2f6..98d3e71cf6 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs @@ -105,13 +105,22 @@ namespace ICSharpCode.WpfDesign.XamlDom /// /// Adds a value at the specified index in the collection. /// - public static void Insert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index) + public static bool Insert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index) { - collectionType.InvokeMember( - "Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, - null, collectionInstance, - new object[] { index, newElement.GetValueFor(null) }, - CultureInfo.InvariantCulture); + var mth = collectionType.GetMethod("Insert", BindingFlags.Public | BindingFlags.Instance, + null, CallingConventions.Any, new Type[]{ typeof(int), typeof(object) }, null); + + if (mth != null) { + collectionType.InvokeMember( + "Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, + null, collectionInstance, + new object[] { index, newElement.GetValueFor(null) }, + CultureInfo.InvariantCulture); + + return true; + } + + return false; } /// @@ -121,7 +130,7 @@ namespace ICSharpCode.WpfDesign.XamlDom internal static bool TryInsert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index) { try { - Insert(collectionType, collectionInstance, newElement, index); + return Insert(collectionType, collectionInstance, newElement, index); } catch (MissingMethodException) { return false; }