{"record":{"id":"86962a2a46a21b5e","repo":"dotnet/wpf","slug":"sr-hwndtarget-hardwarenotsupportduetoprotocolmismatch","errorCode":null,"errorMessage":"SR.HwndTarget_HardwareNotSupportDueToProtocolMismatch","messagePattern":"SR\\.HwndTarget_HardwareNotSupportDueToProtocolMismatch","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs","lineNumber":591,"sourceCode":"            IntPtr hwnd\n            );\n\n        internal void InvalidateRenderMode()\n        {\n            RenderingMode mode =\n                RenderMode == RenderMode.SoftwareOnly ? RenderingMode.Software : RenderingMode.Default;\n\n            //\n            // If ForceSoftwareRendering is set then the transport is connected to a client (magnifier) that cannot\n            // handle our transport protocol version. Therefore we force software rendering so that the rendered\n            // content is available through NTUser redirection. If software is not allowed an exception is thrown.\n            //\n            if (MediaSystem.ForceSoftwareRendering)\n            {\n                if (mode == RenderingMode.Hardware ||\n                    mode == RenderingMode.HardwareReference)\n                {\n                    throw new InvalidOperationException(SR.HwndTarget_HardwareNotSupportDueToProtocolMismatch);\n                }\n                else\n                {\n                    Debug.Assert(mode == RenderingMode.Software || mode == RenderingMode.Default);\n                    // If the mode is default we can chose what works. When we have a mismatched transport protocol version\n                    // we need to fallback to software rendering.\n                    mode = RenderingMode.Software;\n                }\n            }\n\n            //Obtain compatibility flags set in the application\n            bool? enableMultiMonitorDisplayClipping =\n                System.Windows.CoreCompatibilityPreferences.EnableMultiMonitorDisplayClipping;\n\n            if (enableMultiMonitorDisplayClipping != null)\n            {\n                // The flag is explicitly set by the user in application manifest\n                mode |= RenderingMode.IsDisableMultimonDisplayClippingValid;","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs#L573-L609","documentation":"When the process was forced into software rendering (MediaSystem.ForceSoftwareRendering, typically due to a remote-session/protocol mismatch such as RDP without hardware support), setting HwndTarget.RenderMode to Hardware or HardwareReference throws InvalidOperationException (SR.HwndTarget_HardwareNotSupportDueToProtocolMismatch). The request directly contradicts the effective rendering pipeline.","triggerScenarios":"Assigning RenderMode = RenderMode.Hardware (or HardwareReference) while the app is running under a remote session that disabled hardware rendering.","commonSituations":"Apps deployed over RDP/Citrix that hard-code hardware rendering; regression when testing inside remote desktop sessions after working on physical machines.","solutions":["Set RenderMode.Default or RenderMode.SoftwareOnly instead of Hardware in remote-session scenarios","Detect the remote session (SystemParameters.ClientAreaAnimation / GetSystemMetrics(SM_REMOTESESSION)) and skip forcing hardware","Remove ForceSoftwareRendering configuration if hardware is genuinely available and required"],"exampleFix":"// before\nHwndTarget.RenderMode = RenderMode.Hardware; // throws under RDP\n// after\nbool remote = NativeMethods.GetSystemMetrics(0x1000) != 0;\nHwndTarget.RenderMode = remote ? RenderMode.SoftwareOnly : RenderMode.Default;","handlingStrategy":"validation","validationCode":"if (MediaSystem.ForceSoftwareRendering && mode is RenderingMode.Hardware or RenderingMode.HardwareReference)\n    mode = RenderingMode.Default;","typeGuard":"bool IsAssignable(RenderMode m) => m is RenderingMode.Default or RenderingMode.SoftwareOnly;","tryCatchPattern":"try { HwndTarget.RenderMode = mode; } catch (InvalidOperationException) { HwndTarget.RenderMode = RenderMode.SoftwareOnly; }","preventionTips":["Never hard-code RenderMode.Hardware; prefer Default","Detect remote sessions before requesting hardware rendering","Keep rendering-mode selection in one configuration point"],"tags":["wpf","rendering","remote-desktop","hardware"],"backgroundTag":"unsupported-operation","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"}