locked
Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Runtime.InteropServices.ComTypes.IConnectionPointContainer' RRS feed

  • Question

  • After checking that an item is of type Outlook.Mailitem, when it is assigned to another variable declared as Outlook.Mailitem WithEvents, the following error is thrown:

    System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Runtime.InteropServices.ComTypes.IConnectionPointContainer'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B196B284-BAB4-101A-B69C-00AA00341D07}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))

    Is there some way to fix this error?

    Public WithEvents oMailItem As Outlook.MailItem

    Dim oSelection As Microsoft.Office.Interop.Outlook.Selection = oExplorer.Selection
    If TypeOf oSelection.Item(1) Is Microsoft.Office.Interop.Outlook.MailItem Then
              Me.oMailItem = oSelection.Item(1)
    End If
     

     

    I am using VS 2010 and Office 2010.  The add-in is targeting framework 4.

     


    Ajay Agrawal

     

     


    • Edited by ajay006 Wednesday, October 5, 2011 5:08 PM
    Wednesday, October 5, 2011 4:53 PM

All replies

  • Have you tried explicitly casting the objects using TryCast() or DirectCast()? That's the way you normally cast a general object to a specific type of object.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "ajay006" <=?utf-8?B?YWpheTAwNg==?=> wrote in message news:fb11f14b-4565-4e24-85cb-b53e97e85367...

    After checking that an item is of type Outlook.Mailitem, when it is assigned to another variable declared as Outlook.Mailitem WithEvents, the following error is thrown:

    System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Runtime.InteropServices.ComTypes.IConnectionPointContainer'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B196B284-BAB4-101A-B69C-00AA00341D07}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))

    Is there some way to fix this error?

    Public WithEvents oMailItem As Outlook.MailItem

    Dim oSelection As Microsoft.Office.Interop.Outlook.Selection = oExplorer.Selection
    If TypeOf oSelection.Item(1) Is Microsoft.Office.Interop.Outlook.MailItem Then
              Me.oMailItem = oSelection.Item(1)
    End If

     

     

     

     

     

    Ajay Agrawal

    Ken Slovak MVP - Outlook
    • Marked as answer by 许阳(无锡) Tuesday, October 18, 2011 1:37 AM
    • Unmarked as answer by 许阳(无锡) Tuesday, October 18, 2011 1:38 AM
    Wednesday, October 5, 2011 5:44 PM
  • Ken,

    I have tried both DirectCast and TryCast and they both throw the same error.  Documentation for TryCast says that it does not throw an error but instead returns Null (or Nothing in VB.NET I assume) if it cannot cast the object.

    Now I am using TryCast but in a Try-Catch block and setting the object variable to Nothing if an error gets thrown by TryCast.

    Thanks.

    Ajay


    Ajay Agrawal
    Monday, October 17, 2011 9:59 PM
  • That's very strange. Are you sure about that CLSID?
     
     IID '{B196B284-BAB4-101A-B69C-00AA00341D07}'
     
    That's referenced in MSDN as IConnectionPointContainer. It's definitely not the CLSID for an Outlook MailItem
     
    Where is this code running? Is it in an Outlook VSTO COM addin?

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "ajay006" <=?utf-8?B?YWpheTAwNg==?=> wrote in message news:4b0d99b6-48f3-4b43-a6ae-30715bb34c1a...

    Ken,

    I have tried both DirectCast and TryCast and they both throw the same error.  Documentation for TryCast says that it does not throw an error but instead returns Null (or Nothing in VB.NET I assume) if it cannot cast the object.

    Now I am using TryCast but in a Try-Catch block and setting the object variable to Nothing if an error gets thrown by TryCast.

    Thanks.

    Ajay


    Ajay Agrawal

    Ken Slovak MVP - Outlook
    Tuesday, October 18, 2011 1:28 PM
  •  

    The code is running in an Outlook VSTO COM addin.

    I am checking that the object is of type Outlook.MailItem before calling TryCast.


    Ajay Agrawal
    Tuesday, October 18, 2011 3:46 PM
  • Does the same problem happen on more than one machine?
     
    I can't say for sure, but something seems very wrong if TryCast() is throwing an exception. Maybe something with the development machine, or the test computer, but something is either corrupted or not installed or something.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "ajay006" <=?utf-8?B?YWpheTAwNg==?=> wrote in message news:bbbf8e63-f9dd-42f8-8d5e-4a77f41239df...

     

    The code is running in an Outlook VSTO COM addin.

    I am checking that the object is of type Outlook.MailItem before calling TryCast.


    Ajay Agrawal

    Ken Slovak MVP - Outlook
    Tuesday, October 18, 2011 3:49 PM
  • It happens on more than one machine but not on every machine the add-in is installed on.
    Ajay Agrawal
    Wednesday, October 19, 2011 4:24 PM
  • Then it's time for some troubleshooting fun :)
     
    You need to do some detective work to see how the machines where the error occurs differ from those where it does not occur. Check for versions of Office, Outlook, Windows, VSTO runtimes, prerequisites and requirements, and for things you are deploying.
     
    Also look at other Outlook integration code and disable it all to see if the problem stops. If so re-enable the software one at a time until you find the one or ones causing the problem.
     
    Somewhere there are differences that are causing the error.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "ajay006" <=?utf-8?B?YWpheTAwNg==?=> wrote in message news:f0fce543-3b9a-49f2-b79c-5488bdc0f8a1...
    It happens on more than one machine but not on every machine the add-in is installed on.
    Ajay Agrawal

    Ken Slovak MVP - Outlook
    Wednesday, October 19, 2011 5:27 PM
  • I guess I have to start looking at the machines which are throwing the error.

    Does the full trace give you any thoughts where the problem might be:

     

    System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Runtime.InteropServices.ComTypes.IConnectionPointContainer'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B196B284-BAB4-101A-B69C-00AA00341D07}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

       at System.Runtime.InteropServices.ComEventsSink.Advise(Object rcw)
       at System.Runtime.InteropServices.ComEventsInfo.AddSink(Guid& iid)

       at System.Runtime.InteropServices.ComEventsHelper.Combine(Object rcw, Guid iid, Int32 dispid, Delegate d)

       at System.Runtime.InteropServices.ComAwareEventInfo.AddEventHandler(Object target, Delegate handler)

       at AdvisoryPlatform.ThisAddIn.set_oMailItem(MailItem WithEventsValue)

       at AdvisoryPlatform.ThisAddIn.displayDataPanel() in C:\Users\aagrawal\Documents\Visual Studio 2010\Projects\AdvisoryPlatform\AdvisoryPlatform\ThisAddIn.vb:line 467

     

     


    Ajay Agrawal
    Wednesday, October 19, 2011 5:50 PM
  • Sorry, it doesn't tell me much of anything, but that area is not at all my area of expertise.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "ajay006" <=?utf-8?B?YWpheTAwNg==?=> wrote in message news:a897cb3f-0751-4ec1-9223-af1b73a92987...

    I guess I have to start looking at the machines which are throwing the error.

    Does the full trace give you any thoughts where the problem might be:

     

    System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Runtime.InteropServices.ComTypes.IConnectionPointContainer'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B196B284-BAB4-101A-B69C-00AA00341D07}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

       at System.Runtime.InteropServices.ComEventsSink.Advise(Object rcw)
       at System.Runtime.InteropServices.ComEventsInfo.AddSink(Guid& iid)

       at System.Runtime.InteropServices.ComEventsHelper.Combine(Object rcw, Guid iid, Int32 dispid, Delegate d)

       at System.Runtime.InteropServices.ComAwareEventInfo.AddEventHandler(Object target, Delegate handler)

       at AdvisoryPlatform.ThisAddIn.set_oMailItem(MailItem WithEventsValue)

       at AdvisoryPlatform.ThisAddIn.displayDataPanel() in C:\Users\aagrawal\Documents\Visual Studio 2010\Projects\AdvisoryPlatform\AdvisoryPlatform\ThisAddIn.vb:line 467

     

     


    Ajay Agrawal

    Ken Slovak MVP - Outlook
    Wednesday, October 19, 2011 5:54 PM
  • Ajay,

    Did you solve this problem? I have the same case, I cannot find solution.

    Rgrds,

    iziz1

    Sunday, January 22, 2017 10:29 AM
  • Ajay,

    Did you solve this problem? I have the same case, I cannot find solution.

    Rgrds,

    iziz1

    Do you think he is still watching. 

    This thread is from 5 years ago. 

    Create simple a new question and tell than at least what program language you use. 


    Success
    Cor

    Sunday, January 22, 2017 11:59 AM
  • Show the exact code lines where the error is happening.

    Is the addin being run in debug mode or release? Is the addin or Outlook being started using administrative permissions?


    Ken Slovak MVP - Outlook

    Monday, January 23, 2017 2:49 PM