{"record":{"id":"acc2d145937fc6b9","repo":"dotnet/wpf","slug":"sr-format-sr-collection-badtype-this-gettype-name-value-acc2d1","errorCode":null,"errorMessage":"SR.Format(SR.Collection_BadType, this.GetType().Name, value.GetType().Name, \"GeneralTransform3D\")","messagePattern":"SR\\.Format\\(SR\\.Collection_BadType, this\\.GetType\\(\\)\\.Name, value\\.GetType\\(\\)\\.Name, \"GeneralTransform3D\"\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/GeneralTransform3DCollection.cs","lineNumber":504,"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 GeneralTransform3D Cast(object value)\n        {\n            ArgumentNullException.ThrowIfNull(value);\n\n            if (!(value is GeneralTransform3D))\n            {\n                throw new System.ArgumentException(SR.Format(SR.Collection_BadType, this.GetType().Name, value.GetType().Name, \"GeneralTransform3D\"));\n            }\n\n            return (GeneralTransform3D) 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(GeneralTransform3D value)\n        {\n            int index = AddWithoutFiringPublicEvents(value);\n\n            // AddAtWithoutFiringPublicEvents incremented the version\n\n            WritePostscript();\n\n            return index;\n        }","sourceCodeStart":486,"sourceCodeEnd":522,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/GeneralTransform3DCollection.cs#L486-L522","documentation":"Cast is the private gatekeeper for Add/Insert on GeneralTransform3DCollection. It throws ArgumentException (Collection_BadType) when the supplied object is not a GeneralTransform3D. Strongly-typed overloads make this nearly unreachable, but the ICollection/IList non-generic paths accept object and must reject wrong types explicitly.","triggerScenarios":"Calling ((ICollection)collection).Add(someObject) or ((IList)collection).Insert(i, obj) where obj is not a GeneralTransform3D instance; also Add(object) path used by data binding or XAML with a wrong element.","commonSituations":"XAML mistakenly placing a GeneralTransform2D-type resource or a Material into a GeneralTransform3DCollection; reflection-based population code; databinding a mixed list to the collection.","solutions":["Only insert instances of GeneralTransform3D (e.g. RotateTransform3D, TranslateTransform3D, MatrixTransform3D, Transform3DGroup).","Filter before adding: if (item is GeneralTransform3D t) collection.Add(t);","If converting from a 2D transform collection, wrap appropriately or build the intended 3D transforms instead of reusing 2D objects."],"exampleFix":"// before\ncollection.Add((object)rotateTransform2D);\n// after\nif (rotateTransform2D is GeneralTransform3D)\n    collection.Add(rotateTransform2D);\nelse\n    throw new InvalidOperationException(\"Expected a 3D transform\");","handlingStrategy":"type-guard","validationCode":"// before adding via non-generic IList\nif (item is GeneralTransform3D) ((IList)collection).Add(item);","typeGuard":"static bool IsValidItem(object o) => o is GeneralTransform3D;","tryCatchPattern":"try { ((IList)collection).Add(candidate); }\ncatch (ArgumentException ex) when (ex.ParamName == null && ex.Message.Contains(\"GeneralTransform3D\"))\n{\n    // log and skip the invalid item\n}","preventionTips":["Use the generic Add(GeneralTransform3D) overload so the compiler enforces types","Filter XAML/binding input with 'is GeneralTransform3D'","Do not mix 2D and 3D transform collections"],"tags":["wpf","argument-exception","wrong-type","collection"],"backgroundTag":"type-mismatch","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}