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:
[HKEY_CLASSES_ROOT\TypeLib\{00062FFF-0000-0000-C000-000000000046}]
only one Key exists (9.6
)[HKEY_CLASSES_ROOT\Interface\{00063001-0000-0000-C000-000000000046}]
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)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
)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
)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..
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.
User contributions licensed under CC BY-SA 3.0