dotnet/wpf · warning · COMException

0x80040202

0x80040202

Error message

SR.TextStore_CONNECT_E_CANNOTCONNECT

What it means

TextStore implements the TSF (Text Services Framework) ITextStoreAnchor/ACP wrapper. Its ITextStoreAdviseSink.AdviseSink throws COMException 0x80040202 (CONNECT_E_CANNOTCONNECT) when the requested sink IID is not IID_ITextStoreACPSink, i.e. the caller (TSF manager) asked to advise a sink type this store does not support.

Solutions

  1. Ensure the app's text services state is healthy: unfocus/refocus the TextBox so TSF re-advises with the correct IID_ITextStoreACPSink
  2. Disable/test without third-party TSF text service add-ins to identify a mismatched sink provider
  3. Update Windows/IME packs; the failure is on the caller side (TSF), not usually fixable in app code
  4. The HRESULT is returned to TSF which handles it; in app code catch/handle is generally not needed — treat as environmental
Defensive patterns

Strategy: retry

Try / catch

// HRESULT returned to TSF; app-side:
try { inputManagerWork(); } catch (COMException ce) when (ce.ErrorCode == unchecked((int)0x80040202)) { RefocusTextControl(); }

Prevention

When it happens

Trigger: The TSF/IME framework calling AdviseSink with riid other than IID_ITextStoreACPSink on the TextStore associated with a focused TextBox/RichTextBox during text input activation.

Common situations: IME (Input Method Editor) activation on Windows with a non-ACP TSF sink; third-party TSF add-ins or accessibility tools advising unsupported sinks; unusual focus changes during TSF negotiation.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs:78

        #endregion Constructors

        //------------------------------------------------------
        //
        //  Methods - ITextStoreACP
        //
        //------------------------------------------------------

        #region ITextStoreACP

        // See msdn's ITextStoreACP documentation for a full description.
        public void AdviseSink(ref Guid riid, object obj, UnsafeNativeMethods.AdviseFlags flags)
        {
            UnsafeNativeMethods.ITextStoreACPSink sink;

            if (riid != UnsafeNativeMethods.IID_ITextStoreACPSink)
            {
                throw new COMException(SR.TextStore_CONNECT_E_CANNOTCONNECT, unchecked((int)0x80040202));
            }

            sink = obj as UnsafeNativeMethods.ITextStoreACPSink;
            if (sink == null)
            {
                throw new COMException(SR.TextStore_E_NOINTERFACE, unchecked((int)0x80004002));
            }

            // It's legal to replace existing sink.
            if (HasSink)
            {
                Marshal.ReleaseComObject(_sink);
            }
            else
            {
                // Start tracking window movement for _sink.
                _textservicesHost.RegisterWinEventSink(this);
            }

View on GitHub (pinned to 81131a70a4)