{"record":{"id":"49b910bd477ff018","repo":"iOfficeAI/OfficeCLI","slug":"dispid-name-hr-0x-hr-x8","errorCode":null,"errorMessage":"DispId({name}) hr=0x{hr:X8}","messagePattern":"DispId\\((.+?)\\) hr=0x(.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/WordPdfBackend.cs","lineNumber":158,"sourceCode":"                if (s == 1) return;\n                throw new InvalidOperationException();\n            }\n            throw new TimeoutException();\n        }\n        finally { Rel(info); }\n    }\n\n    static int DispId(IntPtr d, string name)\n    {\n        var np = Marshal.StringToHGlobalUni(name);\n        var arr = Marshal.AllocHGlobal(IntPtr.Size);\n        var did = Marshal.AllocHGlobal(4);\n        try\n        {\n            Marshal.WriteIntPtr(arr, np);\n            var iid = Guid.Empty;\n            int hr = VT<F_GetIDsOfNames>(d, 5)(d, ref iid, arr, 1, 0, did);\n            if (hr != 0) throw new InvalidOperationException($\"DispId({name}) hr=0x{hr:X8}\");\n            return Marshal.ReadInt32(did);\n        }\n        finally { Marshal.FreeHGlobal(did); Marshal.FreeHGlobal(arr); Marshal.FreeHGlobal(np); }\n    }\n\n    static void Wv(IntPtr v, object? o)\n    {\n        Marshal.WriteInt64(v, 0); Marshal.WriteInt64(v, 8, 0); Marshal.WriteInt64(v, 16, 0);\n        switch (o)\n        {\n            case null: Marshal.WriteInt16(v, (short)VT_EMPTY); break;\n            case int i: Marshal.WriteInt16(v, (short)VT_I4); Marshal.WriteInt32(v, 8, i); break;\n            case bool b: Marshal.WriteInt16(v, (short)VT_BOOL); Marshal.WriteInt16(v, 8, (short)(b ? -1 : 0)); break;\n            case string s: Marshal.WriteInt16(v, (short)VT_BSTR); Marshal.WriteIntPtr(v, 8, SysAllocString(s)); break;\n            case IntPtr p:\n                Marshal.WriteInt16(v, (short)VT_DISPATCH); Marshal.WriteIntPtr(v, 8, p);\n                if (p != IntPtr.Zero) Marshal.AddRef(p);\n                break;","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/WordPdfBackend.cs#L140-L176","documentation":"Thrown by WordPdfBackend.DispId when IDispatch::GetIDsOfNames returns a non-zero HRESULT for a method/property name. This backend drives Office via raw COM IDispatch (manual vtable + GetIDsOfNames/Invoke), so a failed DispId lookup means the COM object does not expose the requested name. The message embeds the name and the raw HRESULT for diagnosis. The class is [SupportedOSPlatform(\"windows\")] — it is Windows-only Word automation.","triggerScenarios":"Calling DispId against an IDispatch object that lacks the named member: a Word version that renamed/removed the property; querying the wrong interface/object; a member name typo; Office not installed or a different app object than expected.","commonSituations":"Running on a machine without Microsoft Word installed; a Word version with a different object model; passing the wrong dispatch object; a typo in the member name in the interop layer.","solutions":["Decode the HRESULT: common values are DISP_E_UNKNOWNNAME (0x80020006) = name not found, or TYPE_E_ELEMENTNOTFOUND.","Confirm Microsoft Word is installed and the correct ProgID/object is activated.","Verify the member name against the Word object model for the installed version.","Run this backend only on Windows ([SupportedOSPlatform(\"windows\")])."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Guard the platform and Office presence before using the COM PDF backend\nif (!OperatingSystem.IsWindows()) throw new PlatformNotSupportedException(\"WordPdfBackend requires Windows\");\n// Ensure Word is installed (TypeFromProgID) before activating","typeGuard":null,"tryCatchPattern":"try { var did = DispId(dispatch, \"ExportAsFixedFormat\"); /* ... */ }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"DispId\"))\n{ /* ex.Message has name + HRESULT 0x80020006 => member not found on this Word version */ }","preventionTips":["Gate the COM PDF backend behind an OperatingSystem.IsWindows() check.","Verify Word is installed before activating the object.","Cross-check member names against the installed Word version's object model."],"tags":["word","com","interop","windows","pdf"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}