dotnet/wpf · error · InvalidOperationException

SR.AxWindowlessControl

Error message

SR.AxWindowlessControl

What it means

ActiveXSite.ShowObject checks whether the hosted ActiveX control implements IOleInPlaceObjectWindowless (a windowless control). Windowless controls cannot be shown in this hosting model, so the code throws InvalidOperationException(SR.AxWindowlessControl) instead of attempting the show.

Solutions

  1. Use a windowless-aware host (WinForms AxHost with proper windowless site support) instead of this WPF host
  2. Host the control inside a WindowsFormsHost that provides windowed activation
  3. Disable the control's windowless mode (control property/registry) so it activates windowed

Example fix

// before
// windowless Ax control directly in WPF host -> throws
// after
var host = new WindowsFormsHost();
host.Child = new AxMyWindowlessControlWrapper(); // WinForms wrapper provides windowed hosting
Defensive patterns

Strategy: validation

Validate before calling

bool IsWindowless(IOleObject ctrl) => ctrl is UnsafeNativeMethods.IOleInPlaceObjectWindowless;

Type guard

bool SupportsWindowedActivation(object o) => o is not UnsafeNativeMethods.IOleInPlaceObjectWindowless;

Try / catch

try { site.ShowObject(); } catch (InvalidOperationException ex) when (ex.Message.Contains("windowless")) { /* use windowed host */ }

Prevention

When it happens

Trigger: Hosting a windowless ActiveX control (implementing IOleInPlaceObjectWindowless) in a WPF WindowsFormsHost/ActiveX host and triggering in-place activation/ShowObject without a window.

Common situations: Embedding windowless controls (e.g. some video/scripting controls) that expect a windowless container; migrating a WinForms AxHost wrapper into WPF; controls requiring IViewObjectEx windowless support.

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/39ed02b5881b7e04. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/ActiveXSite.cs:182

        int UnsafeNativeMethods.IOleClientSite.ShowObject()
        {
            if (HostState >= ActiveXHelper.ActiveXState.InPlaceActive)
            {
                IntPtr hwnd;
                if (NativeMethods.Succeeded(this.Host.ActiveXInPlaceObject.GetWindow(out hwnd)))
                {
                    if (this.Host.ControlHandle.Handle != hwnd)
                    {
                        if (hwnd != IntPtr.Zero)
                        {
                            this.Host.AttachWindow(hwnd);
                            this.OnActiveXRectChange(this.Host.Bounds);
                        }
                    }
                }
                else if (this.Host.ActiveXInPlaceObject is UnsafeNativeMethods.IOleInPlaceObjectWindowless)
                {
                    throw new InvalidOperationException(SR.AxWindowlessControl);
                }
            }
            return NativeMethods.S_OK;
        }

        int UnsafeNativeMethods.IOleClientSite.OnShowWindow(int fShow)
        {
            return NativeMethods.S_OK;
        }

        int UnsafeNativeMethods.IOleClientSite.RequestNewObjectLayout()
        {
            return NativeMethods.E_NOTIMPL;
        }

        #endregion IOleClientSite

        //

View on GitHub (pinned to 81131a70a4)