{"record":{"id":"0103450f3a7d7780","repo":"wailsapp/wails","slug":"cocreateinstance-failed-with-e-unexpected","errorCode":null,"errorMessage":"CoCreateInstance failed with E_UNEXPECTED","messagePattern":"CoCreateInstance failed with E_UNEXPECTED","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/pkg/w32/ole32.go","lineNumber":68,"sourceCode":"func CoUninitialize() {\n\tprocCoUninitialize.Call()\n}\n\nfunc CoCreateInstance(clsid *syscall.GUID, dwClsContext uintptr, riid *syscall.GUID, ppv uintptr) HRESULT {\n\tret, _, _ := procCoCreateInstance.Call(\n\t\tuintptr(unsafe.Pointer(clsid)),\n\t\t0,\n\t\tuintptr(dwClsContext),\n\t\tuintptr(unsafe.Pointer(riid)),\n\t\tuintptr(ppv))\n\n\tswitch uint32(ret) {\n\tcase E_INVALIDARG:\n\t\tpanic(\"CoCreateInstance failed with E_INVALIDARG\")\n\tcase E_OUTOFMEMORY:\n\t\tpanic(\"CoCreateInstance failed with E_OUTOFMEMORY\")\n\tcase E_UNEXPECTED:\n\t\tpanic(\"CoCreateInstance failed with E_UNEXPECTED\")\n\t}\n\n\treturn HRESULT(ret)\n}\n\nfunc CreateStreamOnHGlobal(hGlobal HGLOBAL, fDeleteOnRelease bool) *IStream {\n\tstream := new(IStream)\n\tret, _, _ := procCreateStreamOnHGlobal.Call(\n\t\tuintptr(hGlobal),\n\t\tuintptr(BoolToBOOL(fDeleteOnRelease)),\n\t\tuintptr(unsafe.Pointer(&stream)))\n\n\tswitch uint32(ret) {\n\tcase E_INVALIDARG:\n\t\tpanic(\"CreateStreamOnHGlobal failed with E_INVALIDARG\")\n\tcase E_OUTOFMEMORY:\n\t\tpanic(\"CreateStreamOnHGlobal failed with E_OUTOFMEMORY\")\n\tcase E_UNEXPECTED:","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/wailsapp/wails/blob/0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3/v3/pkg/w32/ole32.go#L50-L86","documentation":"Error \"CoCreateInstance failed with E_UNEXPECTED\" thrown in wailsapp/wails.","triggerScenarios":"Occurs when CoCreateInstance returns E_UNEXPECTED, indicating a catastrophic failure while creating the COM object instance.","commonSituations":"See trigger scenarios.","solutions":["Treat E_UNEXPECTED from CoCreateInstance as a catastrophic failure; verify the COM runtime was initialized with CoInitializeEx on this thread first.","Ensure the thread's apartment model (STA/MTA) matches what the target component requires."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3","analyzedAt":"2026-08-15T14:17:36.034Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}