{"record":{"id":"17d32d197d0146fd","repo":"MonoGame/MonoGame","slug":"type-newbitmaptype-is-abstract-and-cannot-be-a","errorCode":null,"errorMessage":"Type '{newBitmapType}' is abstract and cannot be allocated.","messagePattern":"Type '(.+?)' is abstract and cannot be allocated\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MonoGame.Framework.Content.Pipeline/Graphics/TextureContent.cs","lineNumber":40,"sourceCode":"        /// <param name=\"faces\">Mipmap chain containing the face collection.</param>\n        protected TextureContent(MipmapChainCollection faces)\n        {\n            Faces = faces;\n        }\n\n        /// <summary>\n        /// Converts all bitmaps for this texture to a different format.\n        /// </summary>\n        /// <param name=\"newBitmapType\">Type being converted to. The new type must be a subclass of BitmapContent, such as PixelBitmapContent or DxtBitmapContent.</param>\n        public void ConvertBitmapType(Type newBitmapType)\n        {\n            ArgumentNullException.ThrowIfNull(newBitmapType);\n\n            if (!newBitmapType.IsSubclassOf(typeof (BitmapContent)))\n                throw new ArgumentException($\"Type '{newBitmapType}' is not a subclass of BitmapContent.\", nameof(newBitmapType));\n\n            if (newBitmapType.IsAbstract)\n                throw new ArgumentException($\"Type '{newBitmapType}' is abstract and cannot be allocated.\", nameof(newBitmapType));\n\n            if (newBitmapType.ContainsGenericParameters)\n                throw new ArgumentException($\"Type '{newBitmapType}' contains generic parameters and cannot be allocated.\", nameof(newBitmapType));\n\n            if (newBitmapType.GetConstructor([typeof (int), typeof (int)]) == null)\n                throw new ArgumentException($\"Type '{newBitmapType} does not have a constructor with signature (int, int) and cannot be allocated.\", nameof(newBitmapType));\n\n            foreach (var mipChain in Faces)\n            {\n                for (var i = 0; i < mipChain.Count; i++)\n                {\n                    var src = mipChain[i];\n                    if (src.GetType() != newBitmapType)\n                    {\n                        var dst = (BitmapContent)Activator.CreateInstance(newBitmapType, src.Width, src.Height)!;\n                        BitmapContent.Copy(src, dst);\n                        mipChain[i] = dst;\n                    }","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/MonoGame/MonoGame/blob/1d71bbd0ff4071a03caa583aa3bc56b85924a819/MonoGame.Framework.Content.Pipeline/Graphics/TextureContent.cs#L22-L58","documentation":"Thrown by TextureContent.ConvertBitmapType(Type) when the supplied type is abstract. ConvertBitmapType calls Activator.CreateInstance to allocate new bitmap instances, which requires a concrete (instantiable) type. Abstract BitmapContent subclasses like the PvrtcBitmapContent base class itself cannot be allocated and will fail here.","triggerScenarios":"Calling texture.ConvertBitmapType(typeof(PvrtcBitmapContent)) or any other abstract BitmapContent subclass. PvrtcBitmapContent is declared as 'public abstract class', so passing it directly fails this check — you must use one of its concrete subclasses.","commonSituations":"Passing the PvrtcBitmapContent base class instead of a concrete PVRTC format subclass; using a custom abstract bitmap base; passing an interface type that happens to satisfy IsSubclassOf via a concrete hierarchy.","solutions":["Use a concrete (non-abstract) subclass: for PVRTC use the specific format type, for standard use PixelBitmapContent<Color>, Dxt1BitmapContent, Dxt3BitmapContent, or Dxt5BitmapContent","Check type.IsAbstract before calling ConvertBitmapType and choose a concrete alternative","Review the class hierarchy — ensure the target type has no abstract keyword"],"exampleFix":"// before\ntexture.ConvertBitmapType(typeof(PvrtcBitmapContent)); // abstract\n\n// after\n// Use a concrete DXT or pixel format instead\ntexture.ConvertBitmapType(typeof(Dxt5BitmapContent));","handlingStrategy":"type-guard","validationCode":"// Ensure the type is concrete (not abstract)\nif (newBitmapType.IsAbstract)\n    throw new ArgumentException($\"{newBitmapType} is abstract; use a concrete subclass\");\ntexture.ConvertBitmapType(newBitmapType);","typeGuard":"static bool IsConcreteBitmapType(Type t) => t.IsSubclassOf(typeof(BitmapContent)) && !t.IsAbstract;","tryCatchPattern":null,"preventionTips":["Use concrete bitmap types: PixelBitmapContent<Color>, Dxt1BitmapContent, Dxt3BitmapContent, Dxt5BitmapContent","Avoid passing the abstract PvrtcBitmapContent base class; use its concrete format subclasses","Check type.IsAbstract at configuration time if selecting types dynamically"],"tags":["texture","content-pipeline","monogame","reflection","validation"],"backgroundTag":null,"analyzedSha":"1d71bbd0ff4071a03caa583aa3bc56b85924a819","analyzedAt":"2026-08-13T17:10:33.625Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}