dotnet/wpf · error

PlatformNotSupportedException

Error message

PlatformNotSupportedException

What it means

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.

Solutions

  1. Run the application on Windows 8.1 or newer
  2. Guard the call with an OS version check and provide a fallback segmenter for older systems
  3. Ensure OSVersionHelper reports the correct version (avoid AppContext/compat shims that mask the real OS version)

Example fix

// before
var segmenter = WordsSegmenter.Create("en-US");
// after
if (OSVersionHelper.IsOsWindows8Point1OrGreater)
{
    var segmenter = WordsSegmenter.Create("en-US");
}
else
{
    // fallback: simple whitespace tokenization or feature disabled
}
Defensive patterns

Strategy: fallback

Validate before calling

if (!OSVersionHelper.IsOsWindows8Point1OrGreater) { /* skip or fallback */ } else { WordsSegmenter.Create(language); }

Type guard

bool CanUseWordsSegmenter => OSVersionHelper.IsOsWindows8Point1OrGreater;

Try / catch

try { segmenter = WordsSegmenter.Create(language); } catch (PlatformNotSupportedException) { segmenter = null; /* use fallback tokenization */ }

Prevention

When it happens

Trigger: Calling WordsSegmenter.Create on a machine running Windows 8.0, Windows 7, or a non-Windows environment where the OS version check fails.

Common situations: 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.

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/8b641c786ff88c89. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/WindowsRuntime/Windows/Data/Text/WordsSegmenter.cs:41

namespace MS.Internal.WindowsRuntime
{
    namespace Windows.Data.Text
    {
        internal partial class WordsSegmenter
        {
            /// <summary>
            /// </summary>
            /// <param name="language"></param>
            /// <returns></returns>
            /// <exception cref="System.ArgumentException"><paramref name="language"/> is not a well-formed language identifier</exception>
            /// <exception cref="System.NotSupportedException"><paramref name="language"/> is not supported</exception>
            /// <exception cref="PlatformNotSupportedException">The OS platform is not supported</exception>
            public static WordsSegmenter Create(string language, bool shouldPreferNeutralSegmenter = false)
            {
                if (!OSVersionHelper.IsOsWindows8Point1OrGreater)
                {
                    throw new PlatformNotSupportedException();
                }
                if (shouldPreferNeutralSegmenter)
                {
                    if (!ShouldUseDedicatedSegmenter(language))
                    {
                        language = Undetermined;
                    }
                }

                return new WordsSegmenter(language);
            }

            private static bool ShouldUseDedicatedSegmenter(string languageTag)
            {
                bool result = true;

                try
                {

View on GitHub (pinned to 81131a70a4)