{"record":{"id":"5a118a23d543d863","repo":"dotnet/wpf","slug":"sr-getresourcestring-srid","errorCode":null,"errorMessage":"SR.GetResourceString(srid)","messagePattern":"SR\\.GetResourceString\\(srid\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/ShaderEffect.cs","lineNumber":372,"sourceCode":"                    {\n                        registerMax = PS_3_0_FLOAT_REGISTER_LIMIT;\n                        srid = nameof(SR.Effect_Shader30FloatConstantRegisterLimit);\n                    }\n                    else if (t == typeof(int))\n                    {\n                        registerMax = PS_3_0_INT_REGISTER_LIMIT;\n                        srid = nameof(SR.Effect_Shader30IntConstantRegisterLimit);\n                    }\n                    else if (t == typeof(bool))\n                    {\n                        registerMax = PS_3_0_BOOL_REGISTER_LIMIT;\n                        srid = nameof(SR.Effect_Shader30BoolConstantRegisterLimit);\n                    }\n                }\n\n                if (registerIndex >= registerMax || registerIndex < 0)\n                {\n                    throw new ArgumentException(SR.GetResourceString(srid), nameof(dp));\n                }\n\n                if (t == typeof(float))\n                {\n                    MilColorF fourTuple;\n                    ConvertValueToMilColorF(newValue, out fourTuple);\n                    StashInPosition(ref _floatRegisters, registerIndex, fourTuple, registerMax, ref _floatCount);\n                }\n                else if (t == typeof(int))\n                {\n                    MilColorI fourTuple;\n                    ConvertValueToMilColorI(newValue, out fourTuple);\n                    StashInPosition(ref _intRegisters, registerIndex, fourTuple, registerMax, ref _intCount);\n                }\n                else if (t == typeof(bool))\n                {\n                    StashInPosition(ref _boolRegisters, registerIndex, (bool)newValue, registerMax, ref _boolCount);\n                }","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/ShaderEffect.cs#L354-L390","documentation":"In UpdateShaderConstant, after determining the register limits for the shader profile (e.g. PS_2_0 vs PS_3_0 constant register maxima, with the srid selecting the matching message such as Effect_Shader30BoolConstantRegisterLimit), a register index outside [0, registerMax) makes the effect throw ArgumentException with the corresponding resource string. The register referenced by PixelShaderConstantCallback does not exist in the shader profile.","triggerScenarios":"Passing a register number >= the profile limit (e.g. register 32+ for float constants in ps_2_0, or bool/int registers with ps_2_0) or a negative register index to PixelShaderConstantCallback.","commonSituations":"Adding many shader parameters and running past the ps_2_0 constant register cap; reusing callback register numbers copied from ps_3_0 samples while the shader is compiled ps_2_0; typo in the register index (off-by-one or negative).","solutions":["Use a register index within the profile limit, or compile the shader with /T ps_3_0 to raise the limits.","Reduce the number of constants (pack values into float4 registers, use arrays) to fit within the limit.","Fix the register index passed to PixelShaderConstantCallback (must be >= 0 and < registerMax)."],"exampleFix":"// before\nnew PropertyMetadata(0f, PixelShaderConstantCallback(45))); // ps_2_0 float limit exceeded\n// after\nnew PropertyMetadata(0f, PixelShaderConstantCallback(12))); // within ps_2_0 limit","handlingStrategy":"validation","validationCode":"// ps_2_0 float register limit is 32; check before registering the callback\nif (registerIndex < 0 || registerIndex >= 32)\n    throw new ArgumentException(\"Constant register index out of range for the shader profile\");","typeGuard":null,"tryCatchPattern":"try\n{\n    effect.ApplyAnimationClock(dp, null); // triggers UpdateShaderConstant path\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"register\"))\n{\n    // remap register index or recompile shader as ps_3_0\n}","preventionTips":["Keep a central constant table mapping parameters to register indices and validate against profile limits.","Pack scalar values into float4 registers to conserve ps_2_0 register space.","Use ps_3_0 when you need more registers or int/bool constants."],"tags":["wpf","shadereffect","register-limit","argument-out-of-range"],"backgroundTag":"value-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}