{"record":{"id":"e62dfa8b7b4f0bc4","repo":"dotnet/wpf","slug":"sr-format-sr-collection-baddestarray-this-gettype-name-e62dfa","errorCode":null,"errorMessage":"SR.Format(SR.Collection_BadDestArray, this.GetType().Name)","messagePattern":"SR\\.Format\\(SR\\.Collection_BadDestArray, this\\.GetType\\(\\)\\.Name\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/GeneralTransform3DCollection.cs","lineNumber":415,"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":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/GeneralTransform3DCollection.cs#L397-L433","documentation":"GeneralTransform3DCollection.CopyTo wraps array writes in a try/catch for InvalidCastException and rethrows it as ArgumentException with Collection_BadDestArray. It means the destination array's element type cannot hold a GeneralTransform3D (e.g. array of a wrong or incompatible type). The library converts this low-level cast failure into a clearer argument error naming the collection type.","triggerScenarios":"Calling CopyTo on a GeneralTransform3DCollection with an Array whose element type is not GeneralTransform3D or a compatible assignable type (e.g. Transform[], object[] is fine, but Transform3D[] or a struct array is not).","commonSituations":"Copying between similarly named collections (2D vs 3D transform collections), legacy code refactored from Transform to GeneralTransform3D, or generic serialization code that allocates arrays from reflected metadata.","solutions":["Allocate the destination array as GeneralTransform3D[] with length >= collection.Count.","If you need a different element type, copy via LINQ: var arr = collection.Cast<TargetType>().ToArray() after verifying convertibility.","Check index + collection.Count stays within the destination array bounds; copy only a compatible subrange."],"exampleFix":"// before\nvar arr = new Transform3D[collection.Count];\ncollection.CopyTo(arr, 0);\n// after\nvar arr = new GeneralTransform3D[collection.Count];\ncollection.CopyTo(arr, 0);","handlingStrategy":"validation","validationCode":"// before CopyTo\nif (destArray == null) throw new ArgumentNullException(nameof(destArray));\nif (destArray is GeneralTransform3D[] typed && typed.Length >= collection.Count && index + collection.Count <= destArray.Length)\n{\n    collection.CopyTo(destArray, index);\n}","typeGuard":"bool IsCompatibleDestArray(Array a, int count) => a is GeneralTransform3D[] && a.Length >= count;","tryCatchPattern":"try { collection.CopyTo(destArray, index); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"array\"))\n{\n    // recreate as GeneralTransform3D[] and retry\n    var typed = new GeneralTransform3D[collection.Count];\n    collection.CopyTo(typed, 0);\n}","preventionTips":["Always allocate CopyTo targets as GeneralTransform3D[]","Verify array length covers index + Count","Never reuse 2D transform arrays for 3D collections"],"tags":["wpf","argument-exception","array-copy","type-mismatch"],"backgroundTag":"incompatible-source-type","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"}