转换 System.ComObject 不再有效

发布于 2024-11-15 19:01:39 字数 368 浏览 3 评论 0原文

我刚刚安装了 ie9,现在我的程序使用 mshtml 的 IHTMLStyle 不再可以转换。

所以我几乎已经拥有

class Style
{
  mshtml.HTMLStyle mStyle;

  Style(mshtml.IHTMLStyle style)
  {
    mStyle = style as mshtml.HTMLStyle
  }
}

并且它曾经有效,但现在 mStyle 总是最终为空。我尝试进行显式转换,即 (mshtml.HTMLStyle)style,但最终不起作用,因为它说样式的实际类型是 System.__ComObject,而我知道它在安装 ie9 之前可以很好地转换。

这听起来像其他人遇到过的事情吗?

I've just installed ie9 and now my program using mshtml's IHTMLStyle no longer can be casted.

so I pretty much had

class Style
{
  mshtml.HTMLStyle mStyle;

  Style(mshtml.IHTMLStyle style)
  {
    mStyle = style as mshtml.HTMLStyle
  }
}

and it used to work, but now mStyle always ends up being null. I tried doing an explicit cast, i.e. (mshtml.HTMLStyle)style, but that ended up not working because it says that the actual type of style is a System.__ComObject when I know it used to cast just fine before I had ie9 installed.

does this sound like anything anyone else has run into?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鱼窥荷 2024-11-22 19:01:39

稍后使用“dynamic”绑定
像这样 :

dynamic mStyle;
void Stylex(mshtml.IHTMLStyle style)
{  
  mStyle = style;
  string test = "";
  //don't work
  test = (mStyle as IHTMLStyle).border;

  //work fine
  test = mStyle.border;
}

private void Test()
{
  var doc = (HTMLDocument)this.editorWebBrowser.Document;
  this.Stylex(doc.body.style); 
}

Use later binding with 'dynamic'
like this :

dynamic mStyle;
void Stylex(mshtml.IHTMLStyle style)
{  
  mStyle = style;
  string test = "";
  //don't work
  test = (mStyle as IHTMLStyle).border;

  //work fine
  test = mStyle.border;
}

private void Test()
{
  var doc = (HTMLDocument)this.editorWebBrowser.Document;
  this.Stylex(doc.body.style); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文