0

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();
halfer
  • 19,824
  • 17
  • 99
  • 186
user3331045
  • 17
  • 1
  • 2

1 Answers1

2

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • I am still not able to figure it out, any further tips. – user3331045 Feb 25 '14 at 06:22
  • Well, what is `oTab`? – David Heffernan Feb 25 '14 at 07:06
  • oTab is an object which is stores System._Comobject that is being returned from getattribute. Strange enough in Ie8 otab is Ienumerable but same code when executed on a system having Ie9 oTab is not Ienumerable.Not able to get whta is the next step i should be taking.Thanks in advance, – user3331045 Feb 25 '14 at 09:46