开发者

Casting a System.ComObject no longer works

开发者 https://www.devze.com 2023-03-13 18:52 出处:网络
I\'ve just installed ie9 and now my program using mshtml\'s IHTMLStyle no longer can be casted. so I pretty much had

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.开发者_StackOverflow社区 (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?


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); 
}
0

精彩评论

暂无评论...
验证码 换一张
取 消