{"record":{"id":"90445b51a599d1e6","repo":"dotnet/wpf","slug":"sr-usesperpixelopacityisobsolete","errorCode":null,"errorMessage":"SR.UsesPerPixelOpacityIsObsolete","messagePattern":"SR\\.UsesPerPixelOpacityIsObsolete","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSourceParameters.cs","lineNumber":301,"sourceCode":"        /// <summary>\n        /// Returns the effective per pixel opacity property given the style and the underlying platform\n        /// </summary>\n        /// <remarks>\n        /// Before Windows 8, Layered child windows were not possible and UsesPerPixelOpacity was ignored when\n        /// WS_CHILD was used. For compatibility reasons:\n        ///   - we introduce UsesPerPixelTransparency which can be set for WS_CHILD windows\n        ///   - we mark as deprecated but still honor UsesPerPixelOpacity\n        /// </remarks>\n        internal bool EffectivePerPixelOpacity\n        {\n            get\n            {\n                if (_usesPerPixelTransparency)\n                {\n                    // Applications aware of the new property should not set the old one too\n                    if (_usesPerPixelOpacity)\n                    {\n                        throw new InvalidOperationException(SR.UsesPerPixelOpacityIsObsolete);\n                    }\n\n                    // If not running on Windows 8, we must clear the parameter for child windows\n                    return PlatformSupportsTransparentChildWindows || ((WindowStyle & NativeMethods.WS_CHILD) == 0);\n                }\n                else\n                {\n                    // Application does not want transparency or else uses old API\n                    // In the second case, we do not support WS_CHILD\n                    return _usesPerPixelOpacity && ((WindowStyle & NativeMethods.WS_CHILD) == 0);\n                }\n            }\n        }\n\n        /// <summary>\n        /// == operator\n        /// </summary>\n        /// <param name=\"a\"></param>","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSourceParameters.cs#L283-L319","documentation":"HwndSourceParameters.UsesPerPixelOpacity is obsolete in favor of UsesPerPixelTransparency. An application that sets both the old UsesPerPixelOpacity and the new UsesPerPixelTransparency throws InvalidOperationException (SR.UsesPerPixelOpacityIsObsolete) because the two settings conflict and the library refuses ambiguous configuration.","triggerScenarios":"Setting UsesPerPixelOpacity = true (the legacy API) and then also setting UsesPerPixelTransparency on the same HwndSourceParameters struct before passing it to HwndSource construction.","commonSituations":"Migrating code from .NET 3.5/4.x per-pixel-opacity APIs to the newer transparency API while keeping old property assignments; copy-pasted sample code that sets both.","solutions":["Remove the UsesPerPixelOpacity assignment and use only UsesPerPixelTransparency","If legacy behavior is required, do not set UsesPerPixelTransparency on the same parameters object"],"exampleFix":"// before\nvar p = new HwndSourceParameters();\np.UsesPerPixelOpacity = true;\np.UsesPerPixelTransparency = true; // throws\n// after\nvar p = new HwndSourceParameters();\np.UsesPerPixelTransparency = true;","handlingStrategy":"validation","validationCode":"if (p.UsesPerPixelOpacity && p.UsesPerPixelTransparency) p.UsesPerPixelOpacity = false;","typeGuard":null,"tryCatchPattern":"try { CreateHwndSource(p); } catch (InvalidOperationException) { /* flags conflict: drop legacy property */ }","preventionTips":["Migrate fully to UsesPerPixelTransparency and delete legacy UsesPerPixelOpacity assignments","Grep for UsesPerPixelOpacity when upgrading frameworks","Centralize HwndSourceParameters construction in one helper"],"tags":["wpf","interop","obsolete-api","transparency"],"backgroundTag":"deprecated-api-usage","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"}