.Except<T> is throwing an Exception

Posted by Jason on Stack Overflow See other posts from Stack Overflow or by Jason
Published on 2010-03-21T00:31:31Z Indexed on 2010/03/21 0:41 UTC
Read the original article Hit count: 484

Filed under:
|
|

I have the following code:

Public Shared Function GetAvailableManufacturers() As List(Of Manufacturer)
    'first get all the live orders and extract their mfrs'
    Dim sos As List(Of OrderForm) = GetFormsByStatus(StockStatus.Building)
    Dim unavailableMfrs As New List(Of Manufacturer)
    For Each so As StockingOrder In sos
        unavailableMfrs.Add(so.Source)
    Next

    'then remove all mfrs with an open SO from a list of all mfrs'
    Dim allMfrs As List(Of Manufacturer) = Manufacturer.GetManufacturers
    Return allMfrs.Except(unavailableMfrs) <----- error here
End Function

Explanation of what the above does:

  • GetFormsByStatus() self-explanatory
  • GetManufacturers() returns a list of all manufacturers in the database

My idea to get available manufacturers was to get a list of all the manufacturers in my open forms, then get a list of all manufacturers and exclude all the manufacturers in the first list, illustrated like so (pseudo):

List A: {1,2,3,4,5,6,7,8,9,10}
List B: {5,7,10}
Result: {1,2,3,4,6,8,9}

I have set up my Manufacturer class according to this article so that it can be compared, but I'm still getting this error:

Unable to cast object of type '<ExceptIterator>d__92'1[csCore.Manufacturer]' to type 'System.Collections.Generic.List'1[csCore.Manufacturer]'.

I thought at first that because during testing GetFormsByStatus() returns 0 results maybe that was causing problems, but it doesn't make sense that Except() wouldn't work if the provided list had 0 items. Can anyone spot what I'm doing wrong?

Thanks so much!

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about LINQ