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

810 views Asked by At

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

enter image description here

The code where this error is looks like that

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?

1

There are 1 answers

3
Albert D. Kallal On

I don't know the details of that COM library. But, use of such in a webforms applications is probably not thread safe.

However, since it "fails" as a few uses?

this suggests you not disposing of the object. You want to do absolute "hand stands" and walk across the valley, the desert, the big valley, and then climb mountains to ensure that the object is disposed after you create, use it, and then are done.

As a result, then wrap your code in a using clause, as that will allow (force) .net to dispose of everything after you use it.

So, say like this (air code warning)

    public void AtemSwitcher()
    {
        using (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();
        }
    }

If the above using block does not help, then hit this with even a larger hammer.

Say this:

    {
        using (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();
            discovery.Dispose()
            releaseObject(discovery)

        }
    }