What to do with System.Runtime.InteropServices.COMException?

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

tejmii

  • Posts: 5
  • Joined: Thu Nov 10, 2022 12:39 pm
  • Real Name: Tomas Mejzr

What to do with System.Runtime.InteropServices.COMException?

PostTue Apr 04, 2023 2:25 pm

I am trying to write webapplication in C# for ATEM Mini using their SDK. Finally i can switch video output, but only 5 times. After that, this error was showed (attachment)

The code where this error is looks like that
Code: Select all
public AtemSwitcher()
        {
            IBMDSwitcherDiscovery discovery = new CBMDSwitcherDiscovery();

            // Connect to switcher
            discovery.ConnectTo("192.168.0.10", out IBMDSwitcher switcher, out _BMDSwitcherConnectToFailure failureReason);
            this.switcher = switcher;
            me0 = this.MixEffectBlocks.First();
        }

The problem is in discovery. Had someone same problem or can someone help me?
Attachments
error.png
error.png (22.52 KiB) Viewed 2668 times
Offline

Cameron Nichols

Blackmagic Design

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

Re: What to do with System.Runtime.InteropServices.COMExcept

PostTue Apr 11, 2023 6:44 am

Hi Tomas,

Each call to IBMDSwitcherDiscovery.ConnectTo will open a new connection with the output IBMDSwitcher object. When the IBMDSwitcher objected is released, then the connection will be closed.

The issue I can see is that in C# managed code, the RCW won't release the COM object straight away, and will only do so when the garbage collector cleans up all unreferenced objects. Because of this you may have exhausted the number of open connections.

To resolve, I suggest calling Marshal.FinalReleaseComObject on the IBMDSwitcher object once you have finished with the object to ensure that the RCW reference count is decremented.

https://learn.microsoft.com/en-us/dotne ... ew=net-7.0

Regards
Cameron
Offline

tejmii

  • Posts: 5
  • Joined: Thu Nov 10, 2022 12:39 pm
  • Real Name: Tomas Mejzr

Re: What to do with System.Runtime.InteropServices.COMExcept

PostSat Apr 15, 2023 9:51 am

Hello Cameron,

thanks a lot for your answer!
It is what I thought. I already solved this problem.

Thanks a lot!

Tomas.

Return to Software Developers

Who is online

Users browsing this forum: RockLight and 11 guests