The non-generic type 'System.Collections.IEnumerable' cannot be used with type arguments

This is an error that was driving me crazy while I was trying to get a recursive LINQ call to work; the fix is ridiculously simple and just an oversight

 First you have to understand that IEnumberable has both generic and not-generic usage.  That was my problem.  In my code, I included the using System.Collections; namespace and in my code I was doing the following:

 IEnumerable <test_order> orders = db.getOrdersByCustomer(1);

Where test_order was type produced with a Linq to Sql Class and getOrdersByCustomer was a Stored Procedure. 

I kept getting the error:

The non-generic type 'System.Collections.IEnumerable' cannot be used with type arguments 

Which basically told me my problem, but I was too blind to see it at first.  Since I was just calling the System.Collections.IEnumerable, and not the System.Collections.Generic.IEnumerable, I was not allowing the use of generics; hence the error.  Simple add the following to you code and you will not have this error any longer: 

using System.Collections.Generic;

Comments (4) -

  • GP
    Thank you!!!!!
  • i love posts that are so simple and sort out these total brain squeeze oversight moments that can cost a lot of time!  thanks very much for the great post.
  • Thanks!!

    Solve my problem in seconds!
  • thank you man thats what i needed
Comments are closed