{"record":{"id":"725d1aba058199df","repo":"dotnet/wpf","slug":"sr-collection-baddestarray-point3dcollection","errorCode":null,"errorMessage":"SR.Collection_BadDestArray","messagePattern":"SR\\.Collection_BadDestArray","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Point3DCollection.cs","lineNumber":380,"sourceCode":"\n            if (array.Rank != 1)\n            {\n                throw new ArgumentException(SR.Collection_BadRank);\n            }\n\n            // Elsewhere in the collection we throw an AE when the type is\n            // bad so we do it here as well to be consistent\n            try\n            {\n                int count = _collection.Count;\n                for (int i = 0; i < count; i++)\n                {\n                    array.SetValue(_collection[i], index + i);\n                }\n            }\n            catch (InvalidCastException e)\n            {\n                throw new ArgumentException(SR.Format(SR.Collection_BadDestArray, this.GetType().Name), e);\n            }\n        }\n\n        bool ICollection.IsSynchronized\n        {\n            get\n            {\n                ReadPreamble();\n\n                return IsFrozen || Dispatcher != null;\n            }\n        }\n\n        object ICollection.SyncRoot\n        {\n            get\n            {\n                ReadPreamble();","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Point3DCollection.cs#L362-L398","documentation":"Point3DCollection.ICollection.CopyTo wraps the SetValue loop in a try/catch and rethrows InvalidCastException as ArgumentException(SR.Collection_BadDestArray) naming the collection type. This occurs when the destination array's element type cannot hold a Point3D value.","triggerScenarios":"Calling the non-generic ICollection.CopyTo with an array whose element type is incompatible, e.g. CopyTo(new Vector3D[n], 0) or CopyTo(new object[...] assigned wrongly / Array of non-assignable type passed as Array).","commonSituations":"Code using the non-generic IList/ICollection interface with arrays of the wrong element type; refactoring changed Point3D to another vector type but not the buffer.","solutions":["Use a Point3D[] destination array or the generic CopyTo(Point3D[], int) overload","Verify the destination array element type is Point3D or object","Catch ArgumentException and inspect InnerException (InvalidCastException) when handling untyped arrays"],"exampleFix":"// before\nArray dest = new Vector3D[count];\n((ICollection)collection).CopyTo(dest, 0); // throws\n// after\nvar dest = new Point3D[count];\ncollection.CopyTo(dest, 0);","handlingStrategy":"type-guard","validationCode":"if (destArray.GetType().GetElementType() != typeof(Point3D) && destArray.GetType().GetElementType() != typeof(object)) throw new ArgumentException(\"bad destination array type\");","typeGuard":"bool CanHoldPoint3D(Array a) { var t = a.GetType().GetElementType(); return t == typeof(Point3D) || t == typeof(object); }","tryCatchPattern":"try { ((ICollection)col).CopyTo(arr, i); }\ncatch (ArgumentException ex) when (ex.InnerException is InvalidCastException) { /* wrong element type; allocate Point3D[] */ }","preventionTips":["Prefer the generic CopyTo(Point3D[], int) overload","Keep buffer element types in sync with collection item type after refactors","Check GetElementType() before untyped copies"],"tags":["wpf","array","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}