title: How ensure only to use correct COM types in code?
body: <p>When I add a COM reference I get an automatically generated interop. In this example I added a reference to MSHTML.</p>
  <p>I had the problem with the following code:</p>
  <pre class="lang-cs prettyprint-override"><code>bool isHtmlFrameElement = activeElement is HTMLFrameElement;
  </code></pre>
  <p>This type test works on target systems that have a proper mshtml interop in the GAC. But on other systems this expression <a href="https://stackoverflow.com/questions/71035209/why-can-i-cast-a-com-object-to-a-wrong-interface">always became true even if it was not an HTMLFrameElement</a>. Correct check would be the following.</p>
  <pre class="lang-cs prettyprint-override"><code>bool isHtmlFrameElement = activeElement is IHTMLFrameElement;
  </code></pre>
  <p>How can I ensure to avoid using <em>invalid</em> types during development?</p>
  <p>My first thoughts on this:</p>
  <ul>
  <li>Post-process the generated interops to make all <em>meta</em> types internal</li>
  <li>Post-process consuming assemblies during build and raise build errors</li>
  </ul>