loads of useful information, examples and tutorials pertaining to web development utilizing asp.net, c#, vb, css, xhtml, javascript, sql, xml, ajax and everything else...

 



Advertise Here
C-Sharpener.com - Programming is Easy!  Learn Asp.Net & C# in just days, Guaranteed!

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

by naspinski 3/23/2008 10:24:00 AM

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;

Currently rated 4.6 by 15 people

  • Currently 4.6/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

c#

Related posts

Comments

1/27/2009 3:41:16 AM

GP
Thank you!!!!!

GP us

4/13/2009 6:19:41 AM

Faraka
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.

Faraka au

7/2/2009 9:40:49 AM

Vítor
Thanks!!

Solve my problem in seconds!

Vítor pt

7/13/2009 10:37:31 PM

ismail
thank you man thats what i needed

ismail tr


Comments are closed