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


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)

    //This is where I get the exception saying
    //cannot access a called object

The Stack trace gives me something like this:

Message=Cannot access a disposed object.
Object name: 'Icon'.

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.

asked on Stack Overflow Mar 26, 2019 by Quack Space Marine • edited Mar 28, 2019 by Lance Li-MSFT

1 Answer


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