How can I catch the exception so it doesn't break?

0

So I'm trying to build an executable. The project I'm running is building on X86.

When I build the project, everything seems fine and I get an executable. But the executable doesn't run. I get an error saying:

'child' is not a child control of this parent.

Followed by, Exception:

Class not registered (Exception from HRESULT: 0X80040154 (REGDB_E_CLASSNOTREG).

I made sure everything is X86 and I cleaned the solution and rebuilt. But I still get these errors. (I tried switching to X64 and Any PC and those options can't even located my DeviceBase.dll) When I started debugging, it took me straight to a specific function of the code.

protected override void Call(bool calling)
{            
    if (calling)
    {
        if (components != null)
        {
            components.Call();
        }                    
    }

    //This is where I get the exception saying
    //cannot access a called object
    base.Call(calling);
}

The Stack trace gives me something like this:

Message=Cannot access a disposed object.
Object name: 'Icon'.
ObjectName=Icon
Source=System.Drawing

The components starts off as null, and calling is initially false. How can I handle this exception in a proper manner? Any advice is appreciated.

c#
visual-studio
exception
asked on Stack Overflow Mar 26, 2019 by Quack Space Marine • edited Mar 28, 2019 by Lance Li-MSFT

1 Answer

0

Thanks for everyone's help. But I had to get device software specific files (.dlls) and set embed interop types to false. That did the trick.

answered on Stack Overflow Mar 28, 2019 by Quack Space Marine

User contributions licensed under CC BY-SA 3.0