mshtml and CLS-compliance

耗尽温柔 提交于 2019-12-12 19:13:58

问题


I am witnessing some odd behaviour with mshtml and CLS-compliance.

I have an assembly marked CLSCompliant(true). This assembly does not expose any types from mshtml publicly.

I can make the code conform to CLS fairly easily, but several things seem to break it:

  1. Introducing a "using mshtml;" statement instead of referencing the namespace manually each time I use a type. For some reason, this breaks CLS compliance.

  2. If I convert the following:

        var doc = webBrowser.Document as mshtml.HTMLDocument;
    
        var scriptNode = doc.createElement("SCRIPT") as mshtml.IHTMLScriptElement;
    
        var nodes = doc.getElementsByTagName("head");
    
        foreach (var head in nodes)
        {
            var htmlHead = (mshtml.HTMLHeadElement)head;
            if (htmlHead != null)
                htmlHead.appendChild((mshtml.IHTMLDOMNode)scriptNode);
        }
    

    to this:

        foreach (var head in nodes.OfType<mshtml.IHTMLDOMNode>())
            head.appendChild((mshtml.IHTMLDOMNode)scriptNode);
    

    This also seems to break CLS compliance.

Can anyone offer any insight as to what might be going on here? Because for me, none of this breaks CLS compliance.

PS When I say breaks CLS compliance, 167 warnings are raised about each type in the mshtml namespace that begins with an underscore, or similar CLS violations.

Thanks.

来源:https://stackoverflow.com/questions/12456256/mshtml-and-cls-compliance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!