'Unable to cast COM object of type 'Microsoft.Office.Interop.Outlook.ApplicationClass' {00063001-0000-0000-C000-000000000046} HRESULT: 0x80040155

I'm having an issue with a very simple piece of C# .NET code which should (for now) simply retrieve the version number of Office installed on the computer running a WinForms application:

var oApp = new Outlook.ApplicationClass();
var outlookVersionString = oApp.Version;

It instantiates the object correct, however when I try and access the Version property, I get the following:

{"Unable to cast COM object of type 'Microsoft.Office.Interop.Outlook.ApplicationClass' to interface type 'Microsoft.Office.Interop.Outlook._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063001-0000-0000-C000-000000000046}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155)."}

I've done a lot of searching online, so a run-through of what I've tried:

  1. Checking that in [HKEY_CLASSES_ROOT\TypeLib\{00062FFF-0000-0000-C000-000000000046}] only one Key exists (9.6)
  2. Checking that this ClassID and version matches in [HKEY_CLASSES_ROOT\Interface\{00063001-0000-0000-C000-000000000046}]
  3. Registering MSOUTL.OLB with C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regtlibv12.exe "C:\Program Files (x86)\Microsoft Office\root\Office16\MSOUTL.OLB" (fails because regtlibv12.exe isn't shipped with VS2017)
  4. Downloading regtlibv12.exe and trying again (fails because 'This app can't run on your PC').
  5. Running C:\Users\uczms>c:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe /TLB "C:\Program Files (x86)\Microsoft Office\root\Office16\MSOUTL.OLB" (fails because it is not a valid .NET Assembly)
  6. Running C:\Users\uczms>c:\Windows\Microsoft.NET\Framework64\v2.0.50727\regasm.exe /TLB "C:\Program Files (x86)\Microsoft Office\root\Office16\MSOUTL.OLB" (fails because it is not a valid .NET Assembly)
  7. Using what worked with the old Interop libraries (edit: note, this does not appear to work with our Office 2016 desktops), which is a subtle change:

var oApp = new Outlook.Application(); var outlookVersionString = oApp.Version;

It might be worth noting that I have a clean Windows 10 Enterprise N Creators Update, and Office 2016 / 365 ProPlus, haven't had any previous versions installed, and haven't downgraded.

I'm not normally a desktop app developer so while I grasp some of these library registration tools, I'm by no means an expert..



Solution 1:[1]

Try to "repair" your Microsoft Office installation. Go to Programs and Features, select Modify and then Repair Online. I had the same issue and this fixed it.

Solution 2:[2]

Some my customers had a similar issues on some PC and the only action that have solved was usign the point 3 "Ensure MSOUTL.LIB is Registered" of this fantastic guide webmakers - Interface not registered (Exception from HRESULT: 0x80040155) – Microsoft Office/Outlook Error, after checked the previous point, obviously. Thanks to Jatin-Auckland for a clear and step by step guide.

Goodluck ;)

Solution 3:[3]

Most likely the very first time you hit that URL in Chrome, you were asked that question, and once you answered yes saying I'll trust this certificate then Chrome no longer asked you this question again.

When you start up in Incognito mode, the browser doesn't use any previously saved information so you are asked to Proceed to the link every time when running in Incognito mode.

I hope that explains it.

Similarly, as a web dev, you'll run into this a often. You'll find AJAX calls fail because your hitting a website that has an untrusted certificate (but the error is cryptic). It's the most confusing thing until you realize what is happening. The fix is to open the URL to the website, answer yes to proceed to the website, and now your AJAX calls will work again. Until Chrome decides that it doesn't trust the website again and you repeat the process.

For me it can be weeks before Chrome decides to untrust a website again so by then I've forgotten the solution. After about 50 times, you catch on and realize the pattern. At least I did. :-)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vaclav T.
Solution 2 Davide Dolla
Solution 3 Dharman