{"record":{"id":"056b87ea6838dc25","repo":"dotnet/wpf","slug":"sr-collection-badtype-transform3dcollection","errorCode":null,"errorMessage":"SR.Collection_BadType","messagePattern":"SR\\.Collection_BadType","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Transform3DCollection.cs","lineNumber":516,"sourceCode":"                DependencyObject inheritanceChild = _collection[i];\n                if (inheritanceChild != null && inheritanceChild.InheritanceContext == this)\n                {\n                    inheritanceChild.OnInheritanceContextChanged(args);\n                }\n            }\n        }\n\n        #endregion\n\n        #region Private Helpers\n\n        private Transform3D Cast(object value)\n        {\n            ArgumentNullException.ThrowIfNull(value);\n\n            if (!(value is Transform3D))\n            {\n                throw new System.ArgumentException(SR.Format(SR.Collection_BadType, this.GetType().Name, value.GetType().Name, \"Transform3D\"));\n            }\n\n            return (Transform3D) value;\n        }\n\n        // IList.Add returns int and IList<T>.Add does not. This\n        // is called by both Adds and IList<T>'s just ignores the\n        // integer\n        private int AddHelper(Transform3D value)\n        {\n            int index = AddWithoutFiringPublicEvents(value);\n\n            // AddAtWithoutFiringPublicEvents incremented the version\n\n            WritePostscript();\n\n            return index;\n        }","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Transform3DCollection.cs#L498-L534","documentation":"The private Cast(object value) helper throws ArgumentException (SR.Collection_BadType) when a value added to the collection is not a Transform3D instance. It is used by the non-generic IList paths (Add/Insert, reached via MaterialCollection-style non-generic callers) after a null check.","triggerScenarios":"Calling the non-generic IList.Add(object) or IList.Insert(int, object) with an object that is not a Transform3D, e.g. adding a Visual3D, a Model3D, or a loosely-typed deserialized object.","commonSituations":"Mixing up 3D object types in code that builds scenes dynamically; passing items from a differently-typed collection; data binding or deserialization that supplies the wrong type.","solutions":["Ensure the object is a Transform3D (e.g. RotateTransform3D, TranslateTransform3D, TransformGroup) before adding.","If the object is a Transform (2D), wrap/convert appropriately or use the correct 3D transform class.","Use the generic Transform3DCollection.Add(Transform3D) so the compiler catches type errors."],"exampleFix":"// before\n((IList)collection).Add(new RotateTransform()); // 2D transform\n// after\n((IList)collection).Add(new RotateTransform3D(new AxisAngleRotation3D(axis, 45)));","handlingStrategy":"type-guard","validationCode":"if (value is Transform3D t) ((IList)collection).Add(t);","typeGuard":"bool IsTransform3D(object v) => v is Transform3D;","tryCatchPattern":"try { ((IList)collection).Add(obj); } catch (ArgumentException) { /* wrong element type; log or convert */ }","preventionTips":["Pattern-match with 'is Transform3D' before non-generic IList calls","Use the generic Add(Transform3D) to get compile-time checks","Watch for 2D/3D transform confusion (RotateTransform vs RotateTransform3D)"],"tags":["wpf","collection","type-mismatch","ilist"],"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"}