{"record":{"id":"61cd9174a644020a","repo":"dotnet/wpf","slug":"sr-compatibilitypreferencessealed-61cd91","errorCode":null,"errorMessage":"SR.CompatibilityPreferencesSealed (FlowDispatcherSynchronizationContextPriority, BaseCompatibilityPreferences)","messagePattern":"SR\\.CompatibilityPreferencesSealed \\(FlowDispatcherSynchronizationContextPriority, BaseCompatibilityPreferences\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/BaseCompatibilityPreferences.cs","lineNumber":135,"sourceCode":"        ///     .Net 4.5, we now record the priority of the DispatcherOperation\n        ///     in the DispatcherSynchronizationContext and use that to satisfy\n        ///     SynchronizationContext.Post and SynchronizationContext.Send\n        ///     calls.  This enables async operations to \"resume\" after an\n        ///     await statement at the same priority they are currently running\n        ///     at.\n        ///\n        ///     This is, of course, an observable change in behavior.\n        /// </summary>\n        public static bool FlowDispatcherSynchronizationContextPriority\n        {\n            get { return _flowDispatcherSynchronizationContextPriority; }\n            set\n            {\n                lock (_lockObject)\n                {\n                    if (_isSealed)\n                    {\n                        throw new InvalidOperationException(SR.Format(SR.CompatibilityPreferencesSealed, \"FlowDispatcherSynchronizationContextPriority\", \"BaseCompatibilityPreferences\"));\n                    }\n\n                    _flowDispatcherSynchronizationContextPriority = value;\n                }\n            }\n        }\n\n        internal static bool GetFlowDispatcherSynchronizationContextPriority()\n        {\n            Seal();\n\n            return FlowDispatcherSynchronizationContextPriority;\n        }\n\n#if NETFX && !NETCOREAPP\n        private static bool _flowDispatcherSynchronizationContextPriority = BinaryCompatibility.TargetsAtLeast_Desktop_V4_5 ? true : false;\n#elif NETCOREAPP\n        private static bool _flowDispatcherSynchronizationContextPriority = true;","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/BaseCompatibilityPreferences.cs#L117-L153","documentation":"BaseCompatibilityPreferences.FlowDispatcherSynchronizationContextPriority is a startup-only knob: once WPF seals BaseCompatibilityPreferences (on first use of the WPF runtime), the setter throws InvalidOperationException with SR.CompatibilityPreferencesSealed naming this property. It exists so the framework can assume settings never change mid-flight.","triggerScenarios":"Setting BaseCompatibilityPreferences.FlowDispatcherSynchronizationContextPriority after Dispatcher/Application initialization, e.g. in App startup handlers, window constructors, or code triggered by the first DispatcherFrame.","commonSituations":"Conditional compatibility tweaks added after the app grew past single-threaded startup; library code trying to flip the flag on behalf of the host app; test fixtures sharing a process where WPF is already initialized.","solutions":["Set the property before any Application/Dispatcher is created — as the first statements of Main or a module initializer.","Document and centralize all BaseCompatibilityPreferences settings in one pre-init location.","Guard with BaseCompatibilityPreferences-style checks or wrap in try-catch when the code may run after init, and skip the assignment."],"exampleFix":"// before\npublic App()\n{\n    BaseCompatibilityPreferences.FlowDispatcherSynchronizationContextPriority = false;\n    InitializeComponent();\n}\n// after\n// in Main(), before constructing App:\nBaseCompatibilityPreferences.FlowDispatcherSynchronizationContextPriority = false;","handlingStrategy":"validation","validationCode":"// Pre-init config step:\nvoid ApplyCompatPreferences()\n{\n    BaseCompatibilityPreferences.FlowDispatcherSynchronizationContextPriority = shouldFlow;\n}","typeGuard":null,"tryCatchPattern":"try { BaseCompatibilityPreferences.FlowDispatcherSynchronizationContextPriority = v; }\ncatch (InvalidOperationException) { log.LogWarning(\"Preferences already sealed; value not applied\"); }","preventionTips":["Set preferences as the very first statements of Main.","Load any config that drives preferences synchronously before WPF init.","Avoid putting preference writes in shared library code."],"tags":["wpf","invalid-state","dispatcher","initialization-order"],"backgroundTag":"invalid-state-transition","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"}