title: LINQ to Objects - Is not in?
body: <p>I have a generic list of custom objects and would like to reduce that list to objects where a specific property value is not in a list of exclusions.</p>
  
  <p>I have tried the following:</p>
  
  <pre><code>Private Sub LoadAddIns()
    // Get add-in templates
    Dim addIns = GetTemplates(TemplateTypes.AddIn)
    // Get the current document
    Dim sectionId As String = CStr(Request.QueryString("sectionId"))
    Dim docId As Integer = CInt(Split(sectionId, ":")(0))
    Dim manual = GetTempManual(docId)
    Dim content As XElement = manual.ManualContent
    // Find which templates have been used to create this document.
    Dim usedTemplates = (From t In content.&lt;header&gt;.&lt;templates&gt;.&lt;template&gt; _
                         Select CInt(t.&lt;id&gt;.Value)).ToList
    // Exclude add-ins that have already been used.
    If usedTemplates IsNot Nothing Then
      addIns = addIns.Where(Function(a) usedTemplates.Contains(a.TemplateID) = False)
    End If
    // Bind available add-ins to dropdown
    With ddlAddIns
      .DataSource = addIns
      .DataTextField = "Title"
      .DataValueField = "TemplateID"
      .DataBind()
      .Items.Insert(0, New ListItem("[select an add-in]", 0))
    End With
  End Sub
  </code></pre>
  
  <p>but get the error:</p>
  
  <blockquote>
    <p>System.InvalidCastException: Unable to cast object of type 
    'WhereListIterator<code>1[MyApp.Classes.Data.Entities.Template]' to type 
    'System.Collections.Generic.List</code>1[MyApp.Classes.Data.Entities.Template]'.</p>
  </blockquote>
  
  <p>How can I select only the templates where the template id is not in the list of exclusions?</p>