C# code works without any issues while accessing outlook items in office 2010 with 32 bit. But when office 2010 is upgraded to office 2013 with 64 bit the code is showing an exception
COMException was unhandled
Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80004023 A Microsoft Software Installer error was encountered. (Exception from HRESULT: 0x80004023)
Here is my code:
Reference -> .Net Tab->Microsoft.Office.Interop.Outlook
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook._NameSpace olNS = oApp.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder oPublicFolder = olNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders);
You should reference version 15 of Microsoft Outlook.
Remember that
The workflow is a little different. Instead of adding a reference to the Microsoft.Office.Interop assemblies as available in the Add Reference dialog, .NET Framework tab, you now use the COM tab
A screenshot from VS 2015 Community
and finally your code lines compiled and working in debug
In particular in your case, you can see such error message when the windows registry is corrupted (old records were left after uninstalling Office).
Try to find any of such Outlook specific records and remove them. Then repair Office and re-start the PC
The following is a possible suggestion from msdn. It seems to be a problem of the Office 2010 uninstaller, which did not remove the COM registration properly.
If so, you can try to rename or remove the following key:
HKEY_CLASSES_ROOT\CLSID\{0006F03A-0000-0000-C000-000000000046}
Please see the ProgId values for Office applications below:
Office Server CLSID key
Access.Application {73A4C9C1-D68D-11D0-98BF-00A0C90DC8D9}
Excel.Application {00024500-0000-0000-C000-000000000046}
FrontPage.Application {04DF1015-7007-11D1-83BC-006097ABE675}
Outlook.Application {0006F03A-0000-0000-C000-000000000046}
PowerPoint.Application {91493441-5A91-11CF-8700-00AA0060263B}
Word.Application {000209FF-0000-0000-C000-000000000046}
User contributions licensed under CC BY-SA 3.0