{"record":{"id":"485f437a29e6b40a","repo":"dotnet/wpf","slug":"sr-effect-shaderpixelshaderset","errorCode":null,"errorMessage":"SR.Effect_ShaderPixelShaderSet","messagePattern":"SR\\.Effect_ShaderPixelShaderSet","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/ShaderEffect.cs","lineNumber":554,"sourceCode":"                        ReleaseResource(oldBrush, channel);\n                        AddRefResource(newBrush, channel);\n                    }\n                }\n            }\n\n            _samplerData[position] = newSampler;\n        }\n\n        private void ManualUpdateResource(DUCE.Channel channel, bool skipOnChannelCheck)\n        {\n            // If we're told we can skip the channel check, then we must be on channel\n            Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel));\n\n            if (skipOnChannelCheck || _duceResource.IsOnChannel(channel))\n            {\n                if (PixelShader == null)\n                {\n                    throw new InvalidOperationException(SR.Effect_ShaderPixelShaderSet);\n                }\n\n                checked\n                {\n                    DUCE.MILCMD_SHADEREFFECT data;\n                    data.Type = MILCMD.MilCmdShaderEffect;\n                    data.Handle = _duceResource.GetHandle(channel);\n\n                    data.TopPadding = _topPadding;\n                    data.BottomPadding = _bottomPadding;\n                    data.LeftPadding = _leftPadding;\n                    data.RightPadding = _rightPadding;\n\n                    data.DdxUvDdyUvRegisterIndex = this.DdxUvDdyUvRegisterIndex;\n                    data.hPixelShader = ((DUCE.IResource)PixelShader).GetHandle(channel);\n\n                    unsafe\n                    {","sourceCodeStart":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/ShaderEffect.cs#L536-L572","documentation":"ShaderEffect requires a PixelShader instance to serialize its state to the render thread (DUCE). During resource update on a composition channel, if PixelShader is null the effect cannot be compiled/uploaded, so WPF throws InvalidOperationException with Effect_ShaderPixelShaderSet.","triggerScenarios":"A ShaderEffect subclass is used in a visual tree and UpdateResource/ManualUpdateResource runs while the PixelShader property has never been set (or was set to null), e.g. the subclass constructor forgot to assign PixelShader or set it after the effect was already attached to an element.","commonSituations":"Custom shader effects where the .ps bytecode was not embedded/loaded (pack URI wrong, resource missing), subclasses that expose a settable PixelShader which a caller nulls, or an effect attached to an element before deferred shader initialization completes.","solutions":["Set the PixelShader property in the ShaderEffect subclass constructor before the effect is used (e.g. PixelShader = new PixelShader { UriSource = new PackUri(\"...ps\") };)","If PixelShader is settable, never assign null; re-create or substitute a default shader instead.","Ensure the compiled .ps file is embedded as a Resource in the assembly so the Pack URI resolves and the shader assignment does not fail silently.","Wrap effect registration in validation that checks PixelShader != null before applying the effect to an element."],"exampleFix":"// before\npublic class MyEffect : ShaderEffect\n{\n    public MyEffect()\n    {\n        UpdateShaderValue(InputProperty);\n    }\n}\n// after\npublic class MyEffect : ShaderEffect\n{\n    public MyEffect()\n    {\n        PixelShader = new PixelShader\n        {\n            UriSource = new Uri(\"pack://application:,,,/MyAssembly;component/Shaders/MyEffect.ps\")\n        };\n        UpdateShaderValue(InputProperty);\n    }\n}","handlingStrategy":"validation","validationCode":"if (effect.PixelShader == null) throw new InvalidOperationException(\"ShaderEffect must have a PixelShader set before use.\");","typeGuard":"static bool HasPixelShader(ShaderEffect e) => e?.PixelShader != null;","tryCatchPattern":null,"preventionTips":["Always assign PixelShader in the ShaderEffect subclass constructor","Verify the .ps file is embedded as Resource and its Pack URI is correct","Never expose a settable PixelShader that can be nulled after attach"],"tags":["wpf","shadereffect","null-reference","rendering"],"backgroundTag":"null-argument","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"}