{"record":{"id":"d218d7f7b11066b9","repo":"ppy/osu","slug":"provided-argument-must-be-of-type-nameof-drawable","errorCode":null,"errorMessage":"Provided argument must be of type {nameof(Drawable)}.","messagePattern":"Provided argument must be of type (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"osu.Game/Skinning/SkinnableContainer.cs","lineNumber":88,"sourceCode":"            LoadComponentAsync(content, wrapper =>\r\n            {\r\n                AddInternal(wrapper);\r\n                components.AddRange(wrapper.Children.OfType<ISerialisableDrawable>());\r\n                ComponentsLoaded = true;\r\n                OnComponentsLoaded?.Invoke(this);\r\n            }, (cancellationSource = new CancellationTokenSource()).Token);\r\n        }\r\n\r\n        /// <inheritdoc cref=\"ISerialisableDrawableContainer\"/>\r\n        /// <exception cref=\"NotSupportedException\">Thrown when attempting to add an element to a target which is not supported by the current skin.</exception>\r\n        /// <exception cref=\"ArgumentException\">Thrown if the provided instance is not a <see cref=\"Drawable\"/>.</exception>\r\n        public void Add(ISerialisableDrawable component)\r\n        {\r\n            if (content == null)\r\n                throw new NotSupportedException(\"Attempting to add a new component to a target container which is not supported by the current skin.\");\r\n\r\n            if (!(component is Drawable drawable))\r\n                throw new ArgumentException($\"Provided argument must be of type {nameof(Drawable)}.\", nameof(component));\r\n\r\n            content.Add(drawable);\r\n            components.Add(component);\r\n        }\r\n\r\n        /// <inheritdoc cref=\"ISerialisableDrawableContainer\"/>\r\n        /// <exception cref=\"NotSupportedException\">Thrown when attempting to add an element to a target which is not supported by the current skin.</exception>\r\n        /// <exception cref=\"ArgumentException\">Thrown if the provided instance is not a <see cref=\"Drawable\"/>.</exception>\r\n        public void Remove(ISerialisableDrawable component, bool disposeImmediately)\r\n        {\r\n            if (content == null)\r\n                throw new NotSupportedException(\"Attempting to remove a new component from a target container which is not supported by the current skin.\");\r\n\r\n            if (!(component is Drawable drawable))\r\n                throw new ArgumentException($\"Provided argument must be of type {nameof(Drawable)}.\", nameof(component));\r\n\r\n            content.Remove(drawable, disposeImmediately);\r\n            components.Remove(component);\r","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/ppy/osu/blob/d9c73e12adff2feaae4a3e158d36fe5883faf6ca/osu.Game/Skinning/SkinnableContainer.cs#L70-L106","documentation":"Thrown by SkinnableContainer.Add when the ISerialisableDrawable passed in is not a Drawable. The container's backing content requires a Drawable to insert into the draw tree; pure interface implementations without Drawable are rejected.","triggerScenarios":"Passing an ISerialisableDrawable implementation that does not derive from Drawable (the framework's Drawable base class) to Add().","commonSituations":"Custom serialisable component implemented as a plain class implementing the interface but not extending Drawable; passing a wrapper/DTO instead of the real component.","solutions":["Ensure the component class inherits from Drawable (and implements ISerialisableDrawable).","Pass the underlying Drawable instance rather than a non-drawable wrapper.","Type-check before Add: if (component is Drawable) container.Add(component); else log error."],"exampleFix":"// before\nclass MyComponent : ISerialisableDrawable { ... } // not a Drawable\ncontainer.Add(new MyComponent());\n\n// after\nclass MyComponent : Drawable, ISerialisableDrawable { ... }\ncontainer.Add(new MyComponent());","handlingStrategy":"type-guard","validationCode":"if (!(component is Drawable))\n    throw new ArgumentException(\"Component must be a Drawable.\");","typeGuard":"static bool IsDrawableComponent(ISerialisableDrawable c) => c is Drawable;","tryCatchPattern":"try { container.Add(component); }\ncatch (ArgumentException) { /* not a Drawable */ }","preventionTips":["Ensure custom components derive from Drawable.","Pass the underlying Drawable, not a wrapper.","Type-check before Add."],"tags":["skinning","skinnable-container","type-mismatch","drawable"],"backgroundTag":null,"analyzedSha":"d9c73e12adff2feaae4a3e158d36fe5883faf6ca","analyzedAt":"2026-08-13T14:12:54.015Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}