{"record":{"id":"892e5afc37d1af41","repo":"stride3d/stride","slug":"error-when-creating-the-material-0","errorCode":null,"errorMessage":"Error when creating the material [{0}]","messagePattern":"Error when creating the material \\[(.+?)\\]","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Rendering/Rendering/Material.cs","lineNumber":72,"sourceCode":"        /// <returns>An instance of a <see cref=\"Material\"/>.</returns>\n        /// <exception cref=\"System.ArgumentNullException\">descriptor</exception>\n        /// <exception cref=\"System.InvalidOperationException\">If an error occurs with the material description</exception>\n        public static Material New(GraphicsDevice device, MaterialDescriptor descriptor, ContentManager content = null)\n        {\n            if (descriptor == null) throw new ArgumentNullException(\"descriptor\");\n\n            // The descriptor is not assigned to the material because\n            // 1) we don't know whether it will mutate and be used to generate another material\n            // 2) we don't wanna hold on to memory we actually don't need\n            var context = new MaterialGeneratorContext(new Material(), device)\n            {\n                GraphicsProfile = device.Features.RequestedProfile,\n            };\n            var result = MaterialGenerator.Generate(descriptor, context, string.Format(\"{0}:RuntimeMaterial\", descriptor.MaterialId));\n\n            if (result.HasErrors)\n            {\n                throw new InvalidOperationException(string.Format(\"Error when creating the material [{0}]\", result.ToText()));\n            }\n\n            var material = result.Material;\n\n            // A material feature can attach references to content instead of loaded objects (such as the\n            // lookup table of the default specular model), and only a content load resolves those.\n            // The generator runs outside of one, so the references are loaded here.\n            foreach (var pass in material.Passes)\n            {\n                pass.Parameters.ResolveAttachedReferences(content, Log);\n            }\n\n            return material;\n        }\n    }\n}\n","sourceCodeStart":54,"sourceCodeEnd":89,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Rendering/Rendering/Material.cs#L54-L89","documentation":"Material.New generates the material compose from its descriptor on the graphics device. If any material feature/attribute reports errors during MaterialGenerator.Generate, the composed result has HasErrors set and New throws InvalidOperationException containing the composed error text.","triggerScenarios":"Calling Material.New with a MaterialDescriptor whose features produce generation errors — e.g. incompatible attributes, missing shaders, unsupported graphics profile features — so MaterialGenerator returns a result with HasErrors == true.","commonSituations":"Custom material attributes referencing missing shader classes; material features unsupported by the device's requested graphics profile; broken asset references in a material descriptor after reorganization.","solutions":["Read the formatted error text in the exception (result.ToText()) to find which material feature/attribute failed","Fix the offending MaterialDescriptor: repair missing shader references or remove the failing attribute","Verify all shaders referenced by the material features compile and exist in the project","Ensure the material's requirements are compatible with GraphicsProfileLevel of the target device","Test the material in the editor (Game Studio) to see the generation errors before runtime"],"exampleFix":"// before: material with a custom attribute pointing to a deleted shader\nvar material = Material.New(device, brokenDescriptor);\n// after: validate shader references exist first\nif (!assetManager.Exists(customAttribute.ShaderSource))\n    customAttribute = fallbackAttribute;\nvar material = Material.New(device, descriptor);","handlingStrategy":"try-catch","validationCode":"// validate descriptor shaders exist before Material.New\nforeach (var attr in descriptor.Attributes.OfType<ShaderMaterialAttribute>())\n    if (!assetManager.Exists(attr.ShaderSource)) throw new InvalidOperationException($\"Missing shader {attr.ShaderSource}\");","typeGuard":null,"tryCatchPattern":"try { material = Material.New(device, descriptor); }\ncatch (InvalidOperationException ex)\n{\n    logger.LogError(ex, \"Material generation failed: {Details}\", ex.Message);\n    material = fallbackMaterial;\n}","preventionTips":["Test all materials in Game Studio before shipping; the editor surfaces the same generation errors","Keep shader class names in material attributes in sync with refactorings","Match material requirements to the target GraphicsProfileLevel"],"tags":["material","runtime","shader-generation","graphics"],"backgroundTag":"schema-validation-failed","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}