Home

Missing Reference

Hello,

I'm attempting to work through some sample code that reads data from a CSV file.

However, when I run the query I receive the following error message;
'System.Collections.IEnumerable' does not contain a definition for 'Skip' and no extension method 'Skip' accepting a first argument of type 'System.Collections.IEnumerable' could be found (press F4 to add a using directive or assembly reference)

Naturally I pressed F4 to add a reference but I can't seem to find one that satisfies this error.

Can someone please point me in the right direction?

Many thanks in advance,

~ Dave

Comments

  • Just a short update; I read on a forum post that I should add a reference to System.Core in my query... but it's not listed anywhere on my pc.

    Any thoughts?

    Thanks,

    ~ Dave
  • No, you don't need to add any references.

    The problem is that you're trying to use a LINQ query operator on a non-generic collection. You need to first apply the Cast or OfType query operator to obtain a generic IEnumerable.
  • Hello Sir,

    Thank you, that worked!

    I changed the example I was following from this;
    var csvData = from row in MyExtensions.ReadFrom(@c:\1900.csv).Skip(1)
    let columns = row.Split(',')
    select new
    {
    Year = int.Parse(columns[0]),
    Make = columns[1],
    Model = columns[2],
    Trim = columns[3]
    };

    csvData.Dump();

    ************************************************

    To this;
    IEnumerable query = MyExtensions.ReadFrom(@c:\1900.csv).OfType();
    var csvData = from row in query.Skip(1)
    let columns = row.Split(',')
    select new
    {
    Year = int.Parse(columns[0]),
    Make = columns[1],
    Model = columns[2],
    Trim = columns[3]
    };

    csvData.Dump();

    Now I'm in business playing... oh, I mean working... on some queries.

    Thanks again!

    ~ Dave
  • I've tried using OfType() but I still get the error 'System.Collections.IEnumerable' does not contain a definition for 'OfType'. What could I possibly be doing wrong now?
Sign In or Register to comment.