{"record":{"id":"e1b9e033f9cb6386","repo":"dotnet/wpf","slug":"sr-collection-badtype-point3dcollection","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/Point3DCollection.cs","lineNumber":453,"sourceCode":"        /// </summary>\n        internal Point3D Internal_GetItem(int i)\n        {\n            return _collection[i];\n        }\n\n\n\n        #endregion\n\n        #region Private Helpers\n\n        private Point3D Cast(object value)\n        {\n            ArgumentNullException.ThrowIfNull(value);\n\n            if (!(value is Point3D))\n            {\n                throw new System.ArgumentException(SR.Format(SR.Collection_BadType, this.GetType().Name, value.GetType().Name, \"Point3D\"));\n            }\n\n            return (Point3D) 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(Point3D value)\n        {\n            int index = AddWithoutFiringPublicEvents(value);\n\n            // AddAtWithoutFiringPublicEvents incremented the version\n\n            WritePostscript();\n\n            return index;\n        }","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Point3DCollection.cs#L435-L471","documentation":"Point3DCollection's private Cast(object) helper (used by IList.Add and IList.Insert) throws ArgumentException(SR.Collection_BadType) when the boxed value is not a Point3D. The non-generic IList surface only accepts Point3D instances.","triggerScenarios":"((IList)point3DCollection).Add(someVector3D) or .Insert(0, otherType) where the object is not a Point3D; null is rejected separately with ArgumentNullException.","commonSituations":"Adding values parsed from XML/JSON into the non-generic IList; generic math code that mixes Point3D and Vector3D; reflection-driven population of collections.","solutions":["Only add Point3D instances via the non-generic IList interface","Use the strongly typed Add(Point3D) method so type errors surface at compile time","Convert/construct a Point3D from the value before inserting"],"exampleFix":"// before\n((IList)collection).Add(new Vector3D(1, 2, 3)); // throws\n// after\ncollection.Add(new Point3D(1, 2, 3));","handlingStrategy":"type-guard","validationCode":"if (value is not Point3D) throw new ArgumentException($\"expected Point3D, got {value?.GetType().Name}\");","typeGuard":"bool IsPoint3D(object v) => v is Point3D;","tryCatchPattern":"try { ((IList)col).Add(value); }\ncatch (ArgumentException) { /* value was not Point3D; convert or reject */ }","preventionTips":["Use the generic Add(Point3D) API to get compile-time checks","Convert external data to Point3D before insertion","Never route mixed-type values through non-generic IList"],"tags":["wpf","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"}