user3331045
user3331045

Reputation: 17

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Collections.IEnumerable'

I am getting the exception below when casting an object as IEnumerable.

This is part of my automation project which was built using VS2008 and was meant to run on IE8, now I am trying to use VS2010 and run on IE9.

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Collections.IEnumerable'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{496B0ABE-CDEE-11D3-88E8-00902754C43A}' failed due to the following error: 'No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))' and the COM component does not support IDispatch::Invoke calls for DISPID_NEWENUM.

 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();

Upvotes: 0

Views: 5638

Answers (1)

David Heffernan
David Heffernan

Reputation: 613302

It's pretty much as the error message says. The object in oTab does not implement IEnumerable. Whatever reasoning led you to assume that it did, is wrong.

Start by inspecting the value of oTab.

Upvotes: 2

Related Questions