Link to home
Start Free TrialLog in
Avatar of djs120
djs120

asked on

Invalid Cast exception with hashtable

I have the following code.  expCollection is a hashtable that contains a collection of classes of type TRI.FarmSelect.Expense:

private void getBudgetItemPrices(Hashtable expCollection, int budgetID, int regionCode)
{
      /* Loop through expenses collection and for each expense find prices/costs and assign */
      foreach(TRI.FarmSelect.Expense expense in expCollection)
      {
            if (DB.getBudgetItemCost(Response, budgetID, regionCode, expense))
            {
                  /* do stuff... */
            }
      }
}

I get a runtime error "Specified cast is not valid" in the foreach statement.  I am positive that the expCollection contains classes of the Expense type.  Why would it give this runtime error? Thanks.
ASKER CERTIFIED SOLUTION
Avatar of b1xml2
b1xml2
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of djs120
djs120

ASKER

Second suggestion worked like a charm (didn't try the first one).  Thanks!