![](/img/trans.png)
[英]: 'Unable to cast COM object of type 'System.__ComObject' to interface type
[英]System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Collections.IEnumerable'
將對象轉換為IEnumerable時,我得到以下異常。
這是我的自動化項目的一部分,它是使用VS2008構建的,並且打算在IE8上運行,現在我正在嘗試使用VS2010並在IE9上運行。
System.InvalidCastException:無法將類型為“System .__ ComObject”的COM對象強制轉換為接口類型“System.Collections.IEnumerable”。 此操作失敗,因為對IID為“{496B0ABE-CDEE-11D3-88E8-00902754C43A}”的接口的COM組件的QueryInterface調用由於以下錯誤而失敗:'不支持此類接口(HRESULT異常:0x80004002(E_NOINTERFACE) )'和COM組件不支持DISPID_NEWENUM的IDispatch :: Invoke調用。
HTMLDocument doc = some htmldocument
IHTMLElement ele = doc.getElementById("some property");
int iTab = (int)ele.getAttribute("someproperty", 0);
object oTab = ele.getAttribute("property", 1);
IEnumerable xyz = (IEnumerable)oTab;
System.Collections.IEnumerator index = xyz.GetEnumerator();
它就像錯誤信息所說的那樣。 oTab
中的對象不實現IEnumerable
。 無論什么推理讓你認為它確實存在,都是錯誤的。
首先檢查oTab
的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.