我在向mshtml.IMarkupServices转换mshtml.HTMLDocumentClass时遇到问题
IHTMLDocument2 doc = new HTMLDocumentClass();
doc.write(new object[] { item.HTMLBody });
IHTMLTxtRange range = ((IHTMLBodyElement)doc.body).createTextRange();
IHTMLTxtRange baseRange = ((IHTMLBodyElement)doc.body).createTextRange();
var markupServices = (IMarkupServices)doc; // <--- exception is thrown here相同的代码在一种情况下可以工作,但在另一种情况下会抛出异常。这些调用是相同的,但在不同的代码位置以不同的方式工作。
发布于 2012-12-06 16:46:01
问题出在ApartmentState上
thread.SetApartmentState(Thread.CurrentThread.GetApartmentState());https://stackoverflow.com/questions/13724946
复制相似问题