Fred2108
Fred2108

Reputation: 3

Unable to cast object to GenericList

The below line of code is giving an exception:

listEmpFullDetails = (List<EmployeeListVM>)listEmpFullDetails.Skip(start).Take(pageSize);

Exception received:

Unable to cast object of type 'd__251[ess.Model.Common.EmployeeListVM]' to type 'System.Collections.Generic.List1

Upvotes: 0

Views: 46

Answers (1)

Simon
Simon

Reputation: 1312

You can't just cast this an iterator to a list. Instead, simply chain a .ToList() at the end, so:

listEmpFullDetails = listEmpFullDetails
    .Skip(start)
    .Take(pageSize)
    .ToList();

Upvotes: 2

Related Questions