{"record":{"id":"f5d134055bbb173c","repo":"dotnet/wpf","slug":"sr-format-sr-compatibilitypreferencessealed-f5d134","errorCode":null,"errorMessage":"SR.Format(SR.CompatibilityPreferencesSealed, \"IsVirtualizingStackPanel_45Compatible\", \"FrameworkCompatibilityPreferences\")","messagePattern":"SR\\.Format\\(SR\\.CompatibilityPreferencesSealed, \"IsVirtualizingStackPanel_45Compatible\", \"FrameworkCompatibilityPreferences\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkCompatibilityPreferences.cs","lineNumber":244,"sourceCode":"        // The 4.5 algorithm had many flaws, leading to infinite loops, scrolling\n        // to the wrong place, and other bad symptoms.  DDCC is worried that fixing\n        // these issues may introduce new compat problems, and asked for a way to opt out\n        // of the fixes.  To opt out, add an entry to the <appSettings> section of the\n        // app config file:\n        //          <add key=\"IsVirtualizingStackPanel_45Compatible\" value=\"true\"/>\n\n        private static bool _vsp45Compat = false;\n\n        internal static bool VSP45Compat\n        {\n            get { return _vsp45Compat; }\n            set\n            {\n                lock (_lockObject)\n                {\n                    if (_isSealed)\n                    {\n                        throw new InvalidOperationException(SR.Format(SR.CompatibilityPreferencesSealed, \"IsVirtualizingStackPanel_45Compatible\", \"FrameworkCompatibilityPreferences\"));\n                    }\n\n                    _vsp45Compat = value;\n                }\n            }\n        }\n\n        internal static bool GetVSP45Compat()\n        {\n            Seal();\n\n            return VSP45Compat;\n        }\n\n        private static void SetVSP45CompatFromAppSettings(NameValueCollection appSettings)\n        {\n            // user can use config file to opt out of VSP fixes\n            string s = appSettings[\"IsVirtualizingStackPanel_45Compatible\"];","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkCompatibilityPreferences.cs#L226-L262","documentation":"Setting FrameworkCompatibilityPreferences.IsVirtualizingStackPanel_45Compatible after the preferences are sealed throws InvalidOperationException. This switch controls whether VirtualizingStackPanel uses .NET 4.5-compatible behavior; WPF seals it once virtualization code has read the preference so panel behavior cannot change mid-run.","triggerScenarios":"Assigning the static IsVirtualizingStackPanel_45Compatible property after WPF has been initialized (first list/virtualization usage, Dispatcher started, or IsSealed == true).","commonSituations":"Setting the switch in a page/window constructor, or attempting to change virtualization behavior after the app has rendered its first VirtualizingStackPanel-based list.","solutions":["Move the assignment to the first line of Main(), before any WPF type is loaded","Guard the assignment with a check of FrameworkCompatibilityPreferences.IsSealed","Remove the runtime toggle and fix the value at build/startup time"],"exampleFix":"// before\nprotected override void OnStartup(StartupEventArgs e)\n{\n    FrameworkCompatibilityPreferences.IsVirtualizingStackPanel_45Compatible = false; // may already be sealed\n}\n\n// after\nstatic void Main()\n{\n    FrameworkCompatibilityPreferences.IsVirtualizingStackPanel_45Compatible = false;\n    var app = new App();\n    app.Run();\n}","handlingStrategy":"validation","validationCode":"if (!FrameworkCompatibilityPreferences.IsSealed)\n    FrameworkCompatibilityPreferences.IsVirtualizingStackPanel_45Compatible = false;","typeGuard":"bool PrefsWritable => !FrameworkCompatibilityPreferences.IsSealed;","tryCatchPattern":"try { FrameworkCompatibilityPreferences.IsVirtualizingStackPanel_45Compatible = v; }\ncatch (InvalidOperationException ex) { log.Warn(ex); }","preventionTips":["Set the switch before any ItemsControl/VirtualizingStackPanel is created","Centralize all compatibility settings in one early startup method","Add a debug assert on IsSealed after the startup method runs"],"tags":["wpf","invalid-state-transition","virtualization"],"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"}