{"record":{"id":"9647034aeb7d5d9a","repo":"dotnet/wpf","slug":"sr-effect-shaderconstanttype","errorCode":null,"errorMessage":"SR.Effect_ShaderConstantType","messagePattern":"SR\\.Effect_ShaderConstantType","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/ShaderEffect.cs","lineNumber":338,"sourceCode":"                                            new UIPropertyMetadata(Effect.ImplicitInput,\n                                                                   PixelShaderSamplerCallback(samplerRegisterIndex,\n                                                                                              samplingMode)));\n        }\n\n\n        // Updates the shader constant referred to by the DP.  Converts to the\n        // form that the HLSL shaders want, and stores that value, since it will\n        // be sent on every update.\n        // We WritePreamble/Postscript here since this method is called by the user with the callback \n        // created in PixelShaderConstantCallback.\n        private void UpdateShaderConstant(DependencyProperty dp, object newValue, int registerIndex)\n        {\n            WritePreamble();\n            Type t = DetermineShaderConstantType(dp.PropertyType, PixelShader);\n\n            if (t == null)\n            {\n                throw new InvalidOperationException(SR.Format(SR.Effect_ShaderConstantType, dp.PropertyType.Name));\n            }\n            else\n            {\n                //\n                // Treat as a float constant in ps_2_0 by default\n                //\n                int registerMax = PS_2_0_FLOAT_REGISTER_LIMIT;\n                string srid = nameof(SR.Effect_Shader20ConstantRegisterLimit);\n\n                if (PixelShader != null && PixelShader.ShaderMajorVersion >= 3)\n                {\n                    //\n                    // If there's a ps_3_0 shader, the limit depends on the type\n                    //\n                    if (t == typeof(float))\n                    {\n                        registerMax = PS_3_0_FLOAT_REGISTER_LIMIT;\n                        srid = nameof(SR.Effect_Shader30FloatConstantRegisterLimit);","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/ShaderEffect.cs#L320-L356","documentation":"UpdateShaderConstant calls DetermineShaderConstantType to map a dependency property's CLR type onto a shader constant register type (float/int/bool/sampler). If the property type is not one of the supported shader constant types, InvalidOperationException with Effect_ShaderConstantType (including the type name) is thrown.","triggerScenarios":"Registering a DependencyProperty whose type is not float/Point/Color/Size/Vector/Matrix/Point3D/Vector3D/Point4D/Quaternion/Size3D/Vector3D/int/bool/etc. (e.g. double, string, custom object) with PixelShaderConstantCallback in a ShaderEffect.","commonSituations":"Declaring a dependency property as double instead of float for a shader parameter; using string or enum-typed properties with PixelShaderConstantCallback; mistyping a brush property as a constant instead of a sampler.","solutions":["Change the dependency property's type to a supported shader constant type (use float, not double, for scalar values).","Convert unsupported types manually: keep the DP as-is but pass a float[] via a separate supported DP, or precompute into float properties.","For brush inputs use PixelShaderSamplerCallback, not PixelShaderConstantCallback.","For int/bool constants ensure the shader is ps_3_0 (see Effect_20ShaderUsing30Registers)."],"exampleFix":"// before\npublic static readonly DependencyProperty StrengthProperty =\n    DependencyProperty.Register(\"Strength\", typeof(double), typeof(MyEffect),\n        new PropertyMetadata(0.0, PixelShaderConstantCallback(0)));\n// after\npublic static readonly DependencyProperty StrengthProperty =\n    DependencyProperty.Register(\"Strength\", typeof(float), typeof(MyEffect),\n        new PropertyMetadata(0f, PixelShaderConstantCallback(0)));","handlingStrategy":"validation","validationCode":"static readonly Type[] SupportedShaderTypes = { typeof(float), typeof(int), typeof(bool), typeof(Point), typeof(Point4D), typeof(Point3D), typeof(Vector), typeof(Vector3D), typeof(Size), typeof(Size3D), typeof(Color), typeof(Matrix), typeof(Quaternion) };\nif (!SupportedShaderTypes.Contains(propType))\n    throw new InvalidOperationException($\"{propType.Name} is not a supported shader constant type\");","typeGuard":"static bool IsShaderConstantType(Type t) =>\n    t == typeof(float) || t == typeof(int) || t == typeof(bool) ||\n    t == typeof(Point) || t == typeof(Point3D) || t == typeof(Point4D) ||\n    t == typeof(Vector) || t == typeof(Vector3D) || t == typeof(Size) ||\n    t == typeof(Size3D) || t == typeof(Color) || t == typeof(Matrix) || t == typeof(Quaternion);","tryCatchPattern":null,"preventionTips":["Use float (not double) for scalar shader constants.","Use PixelShaderSamplerCallback for Brush-typed properties, never PixelShaderConstantCallback.","Remember int/bool constants require ps_3_0 shaders."],"tags":["wpf","shadereffect","type-mismatch","dependency-property"],"backgroundTag":"type-mismatch","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}