{"record":{"id":"8b641c786ff88c89","repo":"dotnet/wpf","slug":"platformnotsupportedexception","errorCode":null,"errorMessage":"PlatformNotSupportedException","messagePattern":"PlatformNotSupportedException","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Windows/Data/Text/WordsSegmenter.cs","lineNumber":41,"sourceCode":"\nnamespace MS.Internal.WindowsRuntime\n{\n    namespace Windows.Data.Text\n    {\n        internal partial class WordsSegmenter\n        {\n            /// <summary>\n            /// </summary>\n            /// <param name=\"language\"></param>\n            /// <returns></returns>\n            /// <exception cref=\"System.ArgumentException\"><paramref name=\"language\"/> is not a well-formed language identifier</exception>\n            /// <exception cref=\"System.NotSupportedException\"><paramref name=\"language\"/> is not supported</exception>\n            /// <exception cref=\"PlatformNotSupportedException\">The OS platform is not supported</exception>\n            public static WordsSegmenter Create(string language, bool shouldPreferNeutralSegmenter = false)\n            {\n                if (!OSVersionHelper.IsOsWindows8Point1OrGreater)\n                {\n                    throw new PlatformNotSupportedException();\n                }\n                if (shouldPreferNeutralSegmenter)\n                {\n                    if (!ShouldUseDedicatedSegmenter(language))\n                    {\n                        language = Undetermined;\n                    }\n                }\n\n                return new WordsSegmenter(language);\n            }\n\n            private static bool ShouldUseDedicatedSegmenter(string languageTag)\n            {\n                bool result = true;\n\n                try\n                {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Windows/Data/Text/WordsSegmenter.cs#L23-L59","documentation":"WordsSegmenter.Create throws PlatformNotSupportedException when the current OS is older than Windows 8.1 (checked via OSVersionHelper.IsOsWindows8Point1OrGreater). The text segmentation APIs this class wraps require WinRT support only available on Windows 8.1 or later.","triggerScenarios":"Calling WordsSegmenter.Create on a machine running Windows 8.0, Windows 7, or a non-Windows environment where the OS version check fails.","commonSituations":"Running WPF apps that use text segmentation on legacy Windows installs, CI containers or Wine environments reporting an unsupported OS version, or testing the package on non-Windows platforms.","solutions":["Run the application on Windows 8.1 or newer","Guard the call with an OS version check and provide a fallback segmenter for older systems","Ensure OSVersionHelper reports the correct version (avoid AppContext/compat shims that mask the real OS version)"],"exampleFix":"// before\nvar segmenter = WordsSegmenter.Create(\"en-US\");\n// after\nif (OSVersionHelper.IsOsWindows8Point1OrGreater)\n{\n    var segmenter = WordsSegmenter.Create(\"en-US\");\n}\nelse\n{\n    // fallback: simple whitespace tokenization or feature disabled\n}","handlingStrategy":"fallback","validationCode":"if (!OSVersionHelper.IsOsWindows8Point1OrGreater) { /* skip or fallback */ } else { WordsSegmenter.Create(language); }","typeGuard":"bool CanUseWordsSegmenter => OSVersionHelper.IsOsWindows8Point1OrGreater;","tryCatchPattern":"try { segmenter = WordsSegmenter.Create(language); } catch (PlatformNotSupportedException) { segmenter = null; /* use fallback tokenization */ }","preventionTips":["Check OSVersionHelper.IsOsWindows8Point1OrGreater before calling","Provide a non-WinRT fallback tokenizer for older OSes","Test the app on the minimum supported Windows version"],"tags":["platform-not-supported","wpf","windows-runtime","os-version"],"backgroundTag":"unsupported-platform","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"}