"Unable to cast COM object" in WPF project

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message

Scott Heimendinger

  • Posts: 2
  • Joined: Mon Dec 18, 2017 6:58 pm

"Unable to cast COM object" in WPF project

PostMon Dec 18, 2017 7:08 pm

Hi there,

I'm attempting to call the DeckLinkAPI from within my WPF application. The code paths are essentially a clone of the CaturePreviewCSharp sample, which works just fine, but in my WPF project I'm hitting a failure right here that I can't seem to get past.

Code: Select all
public DeckLinkDevice(IDeckLink deckLink)
            m_deckLink = deckLink;
            // Get input interface
             m_deckLinkInput = (IDeckLinkInput)m_deckLink;

This returns the error:
System.InvalidCastException: 'Unable to cast COM object of type 'System.__ComObject' to interface type 'DeckLinkAPI.IDeckLinkInput'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{AF22762B-DFAC-4846-AA79-FA8883560995}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).'

My project references the Interop.DeckLinkAPI (v4.0.30319) that shipped with the SDK. The error occurs both when I try to run in x64 and x86. However, the exact same lines run just fine in the [modified, for my needs] CapturePreviewCSharp sample. Both my project and the SDK sample that works are targeting the .NET Framework 4.6.1.

Googling this general exception suggested that I need to use [ComImport] somewhere, but I want to keep the DeckLinkDevice class intact. and I believe those two are mutually exclusive. Or I just don't understand where I need to put that directive.

Any ideas how to unblock this issue? Thank you so much in advance - I've been pounding my head against the wall on this one :-)

Cameron Nichols

Blackmagic Design

  • Posts: 49
  • Joined: Mon Sep 04, 2017 4:05 am

Re: "Unable to cast COM object" in WPF project

PostTue Dec 19, 2017 7:02 am

Hi Scott,

As the DeckLinkDeviceDiscover iterates through all devices, it is possible for this to occur if you have a DeckLink device installed without an input interface (eg DeckLink Mini Monitor)

Best to wrap in try-catch block:
Code: Select all
                // Get input interface
                m_deckLinkInput = (IDeckLinkInput)m_deckLink;
            catch (InvalidCastException)
                // No input interface found, eg in case of DeckLink Mini Monitor

This will be fixed in CapturePreviewCSharp sample in future release.

Is this the likely cause for this exception?

Kind Regards

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 2 guests