GlobalSCAPE Knowledge Base

"System.InvalidCastException" error or emails get stuck in the Outbox

Karla Marsh
Mail Express


  • Mail Express, v3.0


  • "System.InvalidCastException" error occurs when trying to use the Mail Express Outlook Add-in.
  • When using the Mail Express Outlook Add-in, especially when the Add-in is first installed, emails may get stuck in the outbox.  When inspecting the Add-in log file the following message or similar message will be present:
    System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.MAPIFolder'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063006-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).


The Outlook 2003 Add-in requires the Outlook 2003 Primary Interop Assembly (PIA) Microsoft.Office.Interop.Outlook version 11 and the Outlook 2007 Add-in requires the Outlook 2007 PIA Microsoft.Office.Interop.Outlook version 12 to be installed on the computer in the Global Assembly Cache (typically c:\windows\assembly).  If a version of this PIA exists in the Global Assembly Cache that does not correspond to the version of Outlook installed, it is possible that this error may occur.  The Outlook PIA is a COM type library, and COM registration is a "last one wins" model.  Since the Outlook PIAs share the same identifiers across versions, only one PIA can be registered and used on the system at a time. Thus, when the Add-In tries to interact with Outlook through COM, exceptions can occur. For instance, if the Add-In is running in Outlook 2007, and the Add-In tries issuing COM calls to Outlook, it could be erroneously routed to the Outlook 2010 PIA which is not necessarily compatible with Outlook 2007, hence the cast exception.

An example of an environment in which this problem can occur is a workstation with Office 2007 installed and the Office 2007 PIAs, but also the Office 2010 PIAs (version 14) are installed. These may have been installed if Microsoft Office 2010 beta or one of the Office 2010 beta counterparts like Visio 2010 beta or Project 2010 beta were installed. The non-beta version of the Office 2010 installer does not allow multiple versions of Outlook to co-exist on the same machine; hence, only a single Outlook PIA should be installed and registered at one time under normal circumstances. This is also true of the Office 2007 installer.


The correct version of the Outlook PIA needs to be re-registered on the system.  This safest way to accomplish this is to uninstall all versions of Outlook on the system and then to reinstall the version of Outlook that will be used on that workstation and ensure that the .NET Programmability Support feature for Outlook will be installed. The .NET Programmability Support feature can be installed by choosing the Custom install option when prompted by the Office Installer; then expand the Microsoft Office Outlook node and ensure that .NET Programmability Support is set to Run from My Computer.

Last Modified: 10 Years Ago
Last Modified By: GlobalSCAPE 5
Article not rated yet.
Article has been viewed 14K times.
Also In This Category