{"record":{"id":"8be88c60de0dcef3","repo":"stride3d/stride","slug":"cannot-use-nameof-shaderstage-nameof-shaderstage-none","errorCode":null,"errorMessage":"Cannot use {nameof(ShaderStage)}.{nameof(ShaderStage.None)}","messagePattern":"Cannot use (.+?)\\.(.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Direct3D11/CommandList.Direct3D11.cs","lineNumber":292,"sourceCode":"        /// </summary>\n        public void UnsetRenderTargets()\n        {\n            nativeDeviceContext->OMSetRenderTargets(NumViews: 0, ppRenderTargetViews: null, pDepthStencilView: null);\n        }\n\n        /// <summary>\n        ///   Sets a Constant Buffer to the shader pipeline.\n        /// </summary>\n        /// <param name=\"stage\">The shader stage.</param>\n        /// <param name=\"slot\">The binding slot.</param>\n        /// <param name=\"buffer\">The Constant Buffer to set.</param>\n        /// <exception cref=\"ArgumentException\">\n        ///   <paramref name=\"stage\"/> is <see cref=\"ShaderStage.None\"/>. Cannot set a Constant Buffer to an invalid shader stage.\n        /// </exception>\n        internal void SetConstantBuffer(ShaderStage stage, int slot, Buffer buffer)\n        {\n            if (stage == ShaderStage.None)\n                throw new ArgumentException($\"Cannot use {nameof(ShaderStage)}.{nameof(ShaderStage.None)}\", nameof(stage));\n\n            int stageIndex = (int) stage - 1;\n\n            int slotIndex = stageIndex * ConstantBufferCount + slot;\n\n            if (constantBuffers[slotIndex] != buffer)\n            {\n                constantBuffers[slotIndex] = buffer;\n\n                var nativeBuffer = buffer is not null ? buffer.NativeBuffer : default;\n\n                switch (stage)\n                {\n                    case ShaderStage.Vertex: nativeDeviceContext->VSSetConstantBuffers((uint) slot, NumBuffers: 1, ref nativeBuffer); break;\n                    case ShaderStage.Hull: nativeDeviceContext->HSSetConstantBuffers((uint) slot, NumBuffers: 1, ref nativeBuffer); break;\n                    case ShaderStage.Domain: nativeDeviceContext->DSSetConstantBuffers((uint) slot, NumBuffers: 1, ref nativeBuffer); break;\n                    case ShaderStage.Geometry: nativeDeviceContext->GSSetConstantBuffers((uint) slot, NumBuffers: 1, ref nativeBuffer); break;\n                    case ShaderStage.Pixel: nativeDeviceContext->PSSetConstantBuffers((uint) slot, NumBuffers: 1, ref nativeBuffer); break;","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Direct3D11/CommandList.Direct3D11.cs#L274-L310","documentation":"SetConstantBuffer indexes internal constant-buffer arrays with stageIndex = (int)stage - 1, so ShaderStage.None would produce an invalid negative slot range. To prevent corrupt bindings, the method throws ArgumentException when the stage is ShaderStage.None.","triggerScenarios":"Calling SetConstantBuffer(stage, slot, buffer) — directly or via CommandList.BindResources — with a ShaderStage argument that equals ShaderStage.None, typically when a binding descriptor's stage field defaulted to None.","commonSituations":"Building resource binding tables where the stage enum was never assigned (default enum value None); effect/pipeline code that maps pipeline stages but has gaps for some resource types; iterating stages and including a None sentinel in the loop.","solutions":["Pass the actual target shader stage (Vertex, Pixel, Geometry, Compute, etc.) to SetConstantBuffer.","Check where the stage value originates (pipeline description / effect reflection) and fix the mapping that yields None.","Skip bindings whose stage is None instead of forwarding them to the D3D11 CommandList."],"exampleFix":"// before\ncommandList.SetConstantBuffer(ShaderStage.None, slot, constantBuffer);\n// after\ncommandList.SetConstantBuffer(ShaderStage.Vertex, slot, constantBuffer);","handlingStrategy":"validation","validationCode":"if (stage == ShaderStage.None)\n    throw new InvalidOperationException(\"Constant buffer binding requires a concrete ShaderStage\");\ncommandList.SetConstantBuffer(stage, slot, buffer);","typeGuard":"bool HasStage(ShaderStage s) => s != ShaderStage.None;","tryCatchPattern":"try { commandList.SetConstantBuffer(stage, slot, buffer); }\ncatch (ArgumentException ex) when (ex.ParamName == \"stage\") { /* fix stage mapping upstream */ }","preventionTips":["Default binding structs to a real stage, not enum zero (None)","Validate pipeline binding metadata after effect loading","Handle multi-stage resources by emitting one binding per stage"],"tags":["direct3d11","shader-stage","constant-buffer","graphics","argument"],"backgroundTag":"invalid-enum-argument","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"}