{"record":{"id":"a2180af81d3a04b9","repo":"dotnet/wpf","slug":"sr-collection-badtype-generaltransform","errorCode":null,"errorMessage":"SR.Collection_BadType (GeneralTransform)","messagePattern":"SR\\.Collection_BadType \\(GeneralTransform\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/GeneralTransformCollection.cs","lineNumber":506,"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 GeneralTransform Cast(object value)\n        {\n            ArgumentNullException.ThrowIfNull(value);\n\n            if (!(value is GeneralTransform))\n            {\n                throw new System.ArgumentException(SR.Format(SR.Collection_BadType, this.GetType().Name, value.GetType().Name, \"GeneralTransform\"));\n            }\n\n            return (GeneralTransform) 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(GeneralTransform value)\n        {\n            int index = AddWithoutFiringPublicEvents(value);\n\n            // AddAtWithoutFiringPublicEvents incremented the version\n\n            WritePostscript();\n\n            return index;\n        }","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/GeneralTransformCollection.cs#L488-L524","documentation":"Thrown by the private Cast method (used by Add, Insert, and the collection constructor) when the value being added to a GeneralTransformCollection is not a GeneralTransform. The message names the collection type, the offending value's type, and the expected type 'GeneralTransform'.","triggerScenarios":"Calling collection.Add(someObject) or collection.Insert(i, someObject) where someObject is not derived from GeneralTransform — e.g. adding a string, a null-cast object, or a misconfigured XAML resource.","commonSituations":"XAML content mistakes (adding non-transform elements under <TransformGroup> or a GeneralTransformCollection resource), data binding producing the wrong type, or refactors where the wrong collection variable is used.","solutions":["Only add objects deriving from GeneralTransform (e.g. TranslateTransform, RotateTransform, TransformGroup)","Check the object's runtime type with a type guard before Add/Insert","In XAML, verify child elements are transform types and namespaces are correct"],"exampleFix":"// before\ncollection.Add(myVisualBrush); // wrong type\n// after\nif (myVisualBrush is GeneralTransform t) { collection.Add(t); }","handlingStrategy":"type-guard","validationCode":"if (!(value is GeneralTransform)) throw new ArgumentException($\"Expected GeneralTransform, got {value.GetType().Name}\");","typeGuard":"static bool IsGeneralTransform(object o) => o is GeneralTransform;","tryCatchPattern":"try { collection.Add(value); } catch (ArgumentException) { /* value is not a GeneralTransform — handle or log */ }","preventionTips":["Pattern-match with 'is GeneralTransform' before adding","Keep XAML TransformGroup children as transform elements only","Enable XAML compile-time type checking where available"],"tags":["wpf","argumentexception","wrong-type","collection-add"],"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"}