I'm trying to add a reference to 'Microsoft Outlook 16.0 Object Library' in a C# .NET 4.6.1 WPF project, because I have office 2016 installed. Previous versions of the Object Library are incompatible with the 2016 version of office.
If I use Excel's VBA editor, 'Microsoft Outlook 16.0 Object Library' is listed, and exists in C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16010.9126.2116.0_x86_8wekyb3d8bbwe\VFS\ProgramFilesCommonX86\Microsoft Shared\OFFICE16\MSOUTL.OLB, as you can see below:
However, when I use Visual Studio, the COM tab does not list 'Microsoft Office 16.0 Object Library', and when I try to browse to C:\Program Files\WindowsApps, i get 'You dont currently have permission to access this folder', and clicking 'Continue' (to get access) results in 'You have been denied permission to access this folder'.
So basically, the Office 2016 dlls seem to have been tucked away in a folder that is inaccessible to man, dog, and local administrator.
All I'm trying to do is connect to the open Outlook application, and then send an email with an attachment, so perhaps another question to ask is, is there some new fangled way to communicate with Outlook 2016 that hasn't cropped up in my Googleathon?
Also worth noting is that my version of office is installed as a 'Windows Store Application' and therefore does not appear on the usual Add/Remove programs list, so I can't find any 'repair' options for the installation.
Thanks.
Further investigation reveals that I am doing the right thing - trying to add a COM reference to 'Microsoft Outlook 16.0 Object Library' is now the correct way to target Outlook ... https://stackoverflow.com/a/21018418/5040941.
I've checked the GAC, and the assemblies aren't registered. I've done a repair via the 'Apps and Features' right-click start menu option, and they still aren't appearing - it's as if the Windows Store apps just shove their dlls into the Program Files\WindowsApps\* folder, and don't bother to register them in the GAC.
In answer to the much appreciated comments!
Using the following code
Outlook.Application application = (Outlook.Application)Marshal.GetActiveObject("Outlook.Application");
If I use the nuget Microsoft.Office.Interop.Outlook package, i get a System.Runtime.InteropServices.COMException: 'Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))' exception.
If I try using Microsoft Outlook 15.0 Object Library or Microsoft Outlook 14.0 Object Library references via the Assemblies/Extensions tab of Add Reference, I get a System.Runtime.InteropServices.COMException: 'Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))' exception.
I don't think accessing the WindowsApps folder is the way to go.
Firstly, it's locked down for some reason which typically indicates the potential for trouble if i start digging around and changing security permissions, not to mention the fact that maintaining a copy of the latest dll in my solution will undoubtedly add unnecessary complexity to my project.
Secondly, but more importantly, if I have office installed, and I can access 'Microsoft Outlook 16.0 Object Library' from Excel Vba, then why can't I access it from Visual Studio?
There is obviously some issue with the installation not registering the dlls properly, only Excel has some trick it uses to make the reference available anyway.
Has anyone reading this managed to install Office 365/2016 Windows Store and found a reference to 'Microsoft Outlook 16.0 Object Library' in Visual Studio?
Am I the only with this problem?! Because it affects multiple computers in my office running Windows 10 and Office 365 ...
In answer to RogerN (thanks), please see the image below - I don't have Microsoft.Office.Interop.Outlook version 16 listed, and Microsoft.Office.Core isn't listed either.
If I try to use the v15 library, I get the following error:
System.Runtime.InteropServices.COMException
HResult=0x80040154
Message=Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
Source=mscorlib
*AND THE ANSWER IS *
The two computers I bought from Dell are 64 bit, but they come preinstalled with 32 bit, windows store versions of MS Office 2016/365.
In order to fix the problem, I had to:
uninstall the store app from Settings > Apps > Apps&Features > Microsoft Office Desktop Apps > Uninstall
log into portal.office.com
select install office apps, advanced, choosing the 64-bit version
Quite why Dell think we want 32 bit versions installed on 64 bit machines, or why someone from Microsoft hasn't posted a solution to this problem, is beyond my understanding, but nevertheless, RogerN was correct. Thanks to everyone for taking time out their days to help me out.
Elaborating on my earlier comment: From what you've described, it sounds like you've installed a 32-bit version of Microsoft Office on a 64-bit machine. Only 32-bit COM objects would have been registered, and therefore a 64-bit .NET application would be unable to find them. If you search your registry, you ought to find that the 0006F03A-0000-0000-C000-000000000046 class ID is only registered under the Wow6432Node.
To resolve the issue, you could either install the 64-bit version of Office or force your .NET application to target the x86 platform.
I have developed a windows service that would read doc / docx files and replace values based on database records and convert the replaced document as PDF.
Used Microsoft Office Interop DLL for the conversion. The service is hosted in two different machines ( Win Server 2008 R2 Enterprise - 64 Bit ). I had to
set the Identity as Interactive User in DCOM settings to solve the exception :
Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046}failed due to the following error: 8000401a.
Initially I couldn't not find the DCOM entry for Microsoft Windows Document. So I had to change some settings in the registry following this link. This got me working in one system ( the service working fine). However, in another system, the service threw an exception Attempted to read or write protected memory. This is often an indication that other memory is corrupt on WorkDocument.ClearFormatting() code.
To overcome that I had changed the build properties form "Any CPU" to "x86". The service worked fine for some times but it just started to throw the exception (Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 8000401a) again. I could not figure out when the service starts throwing this exception. If I restart the service it works normal but not for too long.
I know using MS interop is not recommended for services. But i came to know about this issue only after the complete development of the service as I had no problems running the program as windows application on my system for testing purposes.
Tried with google and have even solved the issue but the solution seems to be a temporary one for one server and the other seems to work fine. Kindly guide me to overcome the situation.
Thanks
I have an C# winform app compiled for x86 platform, using excel 2003 COM interop libraries. The Visual studio project references the following interop files for office 2003)
Microsoft.Office.Interop.Excel.dll (v 11.0.0, specific version = true)
Microsoft.Vbe.Interop.dll (v 11.0.0, specific version = false)
This application runs fine on most computers with excel 2003,2007 and 2010, but one of the users reported the exception below to me.
This users has windows 7 and Office 2010
System.InvalidCastException: Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
at Microsoft.Office.Interop.Excel.ApplicationClass.get_Workbooks()
From what I've read, this problem can occurs with conflicting versions of Office, but as I'm specifically referencing the 2003 Office PIAs and distributing them alongside the application, I'm unsure of what can cause the problem.
Thanks
The user's registry is broken. He has Office installed or you would have never been able to get the Aplication object created but it is missing an entry in the Typelib registry key. It is required to allow the interop call to succeed.
Reinstalling Office is the sane and simple solution. This kind of lossage is rarely isolated.
I have a web application that create an access database. When I want to create this database, I add Microsoft.Office.Interpob.access.dao.dll from COM references.
This application work in my pc very well. But when I put this application in the customer server I get this error:
Retrieving the COM class factory for component with CLSID {CD7791B9-43FD-42C5-AE42-8DD2811F0419} failed due to the following error: 80040154
Note that the Microsoft Office Access is not install in customer server. Must I Install this program on this server or can I add some dll to resolve this problem or I have to do anything else?
Thanks.
Check out these links, they might help:
social.msdn.microsoft.com - "Error 80040154 retreiving COM Class factory"
asp.net - "Retrieving COM class factory failed due to the following error: 80040154"
software602.com - "KB987: Error code 80040154. Class not registered"
I know this is a little late for the the original poster, but hopefully this will be useful to others. The correct answer is:
No, you don't need to install Microsoft Office Access on the server.
But, you do need to install the Microsoft Office Access Runtime on the server. From my limited experience it doesn't seem to matter which office runtime - I had the 2013 runtime installed locally but when I installed the runtime on my server it was fine with the 2016 runtime (so both installed the required COM object). In my case I was installing the x64 version.
The Microsoft Office Access Runtime is free from Microsoft.
The Microsoft Access 2013 Runtime can be downloaded from: https://www.microsoft.com/en-gb/download/details.aspx?id=39358
The Microsoft Access 2016 Runtime can be downloaded from https://www.microsoft.com/en-gb/download/details.aspx?id=50040
I have a legacy app that captures signatures. It uses Microsoft.Ink.dll that came from a Windows Tablet SDK. I am maintaining the app on Windows 7 VS 2010 and it runs fine on my box. When I deploy the app to Windows Server 2003 the app fails with the following error:
Exception during StringFormat: Index (zero based) must be greater than or equal to zero and less than the size of the argument list. Datapump error on interface Risk Assessment Signatures: Retrieving the COM class factory for component with CLSID {937C1A34-151D-4610-9CA6-A8CC9BDB5D83} failed due to the following error: 80040154.
Regsvr32 on the dll fails.
I assume that this is because related dll's are missing.
Is there any way to delete the old ink dll and use a more modern dll that I can properly deploy? If not what is the best way to deploy this app?