{"record":{"id":"a756906ee17bf35b","repo":"stride3d/stride","slug":"shadermixinsource-must-have-a-name","errorCode":null,"errorMessage":"ShaderMixinSource must have a name","messagePattern":"ShaderMixinSource must have a name","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Effects/Compiler/EffectCompilerBase.cs","lineNumber":64,"sourceCode":"            }\n            else\n            {\n                mixinToCompile = shaderSource as ShaderMixinSource;\n                var shaderClassSource = shaderSource as ShaderClassCode;\n\n                if (shaderClassSource != null)\n                {\n                    mixinToCompile = new ShaderMixinSource { Name = shaderClassSource.ClassName };\n                    mixinToCompile.Mixins.Add(shaderClassSource);\n                }\n\n                if (mixinToCompile == null)\n                {\n                    throw new ArgumentException(\"Unsupported ShaderSource type [{0}]. Supporting only ShaderMixinSource/sdfx, ShaderClassSource\", \"shaderSource\");\n                }\n                if (string.IsNullOrEmpty(mixinToCompile.Name))\n                {\n                    throw new ArgumentException(\"ShaderMixinSource must have a name\", \"shaderSource\");\n                }\n            }\n\n            // Compile the whole mixin tree\n            var compilerResults = new CompilerResults { Module = $\"EffectCompile [{mixinToCompile.Name}]\" };\n            var effectInputHash = ShaderMixinObjectId.Compute(mixinToCompile, compilerParameters.EffectParameters);\n            var bytecode = Compile(mixinToCompile, effectParameters: compilerParameters.EffectParameters, compilerParameters, effectInputHash);\n\n            // Since bytecode.Result is a struct, we check if any of its member has been set to know if it's valid\n            if (bytecode.Result.CompilationLog is not null || bytecode.Task is not null)\n            {\n                bytecode.Result.CompilationLog?.CopyTo(compilerResults);\n                compilerResults.Bytecode = bytecode;\n                compilerResults.SourceParameters = new CompilerParameters(compilerParameters);\n            }\n            return compilerResults;\n        }\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Effects/Compiler/EffectCompilerBase.cs#L46-L82","documentation":"After resolving the ShaderMixinSource to compile, EffectCompilerBase.Compile requires its Name to be non-empty, because the name is used for cache keys, module naming and generated shader lookup. An anonymous mixin cannot be addressed, so an ArgumentException is thrown.","triggerScenarios":"Calling Compile with a ShaderMixinSource whose Name property was never set (or set to null/empty string), typically when building mixins manually.","commonSituations":"Hand-constructed ShaderMixinSource objects in effect codegen or unit tests; object initializers that forget Name; deserialization losing the Name field.","solutions":["Set the Name property of the ShaderMixinSource to the shader class name before calling Compile.","Populate Name from the primary ShaderClassSource.ClassName when wrapping class sources.","Add an assertion/debug check on mixin.Name in your effect-building code."],"exampleFix":"// before\nvar mixin = new ShaderMixinSource();\nmixin.Mixins.Add(new ShaderClassSource(\"MyShader\"));\n// after\nvar mixin = new ShaderMixinSource { Name = \"MyShader\" };\nmixin.Mixins.Add(new ShaderClassSource(\"MyShader\"));","handlingStrategy":"validation","validationCode":"if (mixin == null || string.IsNullOrEmpty(mixin.Name)) throw new InvalidOperationException(\"ShaderMixinSource must be named before Compile\");","typeGuard":"bool HasName(ShaderMixinSource m) => !string.IsNullOrEmpty(m?.Name);","tryCatchPattern":"try { compiler.Compile(mixin, parameters); } catch (ArgumentException ex) when (ex.Message == \"ShaderMixinSource must have a name\") { /* set mixin.Name and retry */ }","preventionTips":["Use object initializers that always set Name","Derive Name from ShaderClassSource.ClassName","Validate mixins in a central factory method"],"tags":["shaders","argument-validation","empty-name"],"backgroundTag":"empty-required-field","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}