I have a .NET program, that interacts with a mshtml object from another process. I wrote a small sample project from scratch to illustrate the problem. In this example I directly use a COM reference for the mshtml interop.
HTMLDocument document = Document;
IHTMLElement activeElement = document.activeElement;
Log.Verbose(activeElement.tagName);
bool isHtmlFrameElement = activeElement is HTMLFrameElement;
Log.Verbose("active Element is " + (isHtmlFrameElement ? "" : "NOT ") + "a frame element");
I reference a custom mshtml, generated with the following call:
tlbimp c:\Windows\System32\mshtml.tlb /out:c:\tmp\Interop.mshtml.dll
On my dev machine (where Office is installed) I get this log which is the expected behavior:
INPUT
active Element is NOT a frame element
But on a naked machine, where no office (and no mshtml interop) is installed I get the following log:
INPUT
active Element is a frame element
Of course it is not an HTMLFrameElement
and any access to one of it's members causes a member not found exception.
Why does COM allow this invalid cast in the second scenario? Can I work with my interop (in the build dir) or do I have to install it to GAC (like MS Office does)?