关于Microsoft.mshtml.dll文件的部署问题


前几天用C#做一个网页的浏览和编辑器,在开发及其运行良好,但是当部署到客户机器的时候发生了找不到Microsoft.mshtml.dll的错误提示,只好重新发布的时候选择把Microsoft.mshtml.dll复制到本地,然后再次部署,还是同样的问题,但是Microsoft.mshtml.dll文件明明就在程序的根目录下面,但是就是找不到。。。

后来在网上找到原因,这个文件应该使用如图:

否则就要部署到指定的目录才能够识别到的。。。

很开心,继续下一步了,这时能够找到文件Microsoft.mshtml.dll了,但是报了另外一个异常:

Unable to cast COM object of type ‘System.__ComObject’ to class type

‘mshtml.HTMLDocumentClass’. COM components that enter the CLR and do not support

IProvideClassInfo or that do not have any interop assembly registered will be wrapped in the

__ComObject type. Instances of this type cannot be cast to any other class; however they can

be cast to interfaces as long as the underlying COM component supports QueryInterface calls

for the IID of the interface.

翻译下:

无法将类型为“System.__ComObject”的 COM 对象强制转换为类类型“mshtml.HTMLDocumentClass”。进入 CLR 且不支持 IProvideClassInfo 或没有注册任何互操作程序集的 COM 组件都将包装在 __ComObject 类型中。这种类型的实例不能强制转换为任何其他类;不过,只要基础 COM 组件支持对接口 IID 的 QueryInterface 调用,就能将这些实例强制转换为接口。

看上去问题出在了HTMLDocumentClass,找到自己程序使用HTMLDocumentClass的地方,统统换成了HTMLDocument,它提示不让用HTMLDocumentClass那么就用HTMLDocument。

解决。 嘎嘎。
暂无问题。。。


《 “关于Microsoft.mshtml.dll文件的部署问题” 》 有 4 条评论

  1. 此问题为IE版本兼容性问题,我也遇到了类似问题,后来
    一律使用IHTMLElement 解决。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

验证码 * Time limit is exhausted. Please reload CAPTCHA.