InvalidCastException

I am trying to get the list of all variables from variable list that are connected to an excel list, but i keep getting an exception "Unable to cast COM object of type 'System.__ComObject' to class type "SolidEdgeFramework.variable".