Shell32 call fails from an event handler, but works from Main

0

I hope the explanation makes sense. I have a line

(new Shell()).NameSpace(TargetDirectory).CopyHere(SourceFile, 16 | 2048);

It works just fine when I'm calling it sequentially. Meaning I have my Main method and in that, I call the method that contains the line. What doesn't work is calling the containing method from an event. I have a FileSystemWatcher and in it's Changed event, I call the method containing this line. Then I get

System.InvalidCastException: 'Unable to cast COM object of     type 'System.__ComObject' to interface type 'Shell32.Shell'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{34936BA1-67AD-4C41-99B8-8C12DFF1E974}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).'

And here's where I'm stuck. I now that line itself works just fine so I've no idea what to repair and how.

c#
com-interop
asked on Stack Overflow Jan 31, 2018 by ReBoot

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0