Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 183139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:03:47+00:00 2026-05-11T15:03:47+00:00

I have a generic list of custom objects and would like to reduce that

  • 0

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.

I have tried the following:

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.<header>.<templates>.<template> _                        Select CInt(t.<id>.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 

but get the error:

System.InvalidCastException: Unable to cast object of type ‘WhereListIterator1[MyApp.Classes.Data.Entities.Template]' to type 'System.Collections.Generic.List1[MyApp.Classes.Data.Entities.Template]’.

How can I select only the templates where the template id is not in the list of exclusions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:03:47+00:00Added an answer on May 11, 2026 at 3:03 pm

    Tack a ToList() extension to the end of the Where extension to convert it back to a List of the appropriate type.

    If usedTemplates IsNot Nothing Then     addIns = addIns.Where(Function(a) usedTemplates.Contains(a.TemplateID) = False) _                    .ToList() End If 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Generic List of objects that I've bound to a custom control.
I have a system.collections.generic.list(of ListBox) I would like to use the collection classes built-in
I have a Powershell script where I would like to create a generic List
I have a project that is using a generic list of a custom class.
I have a custom list which inherits from Generic.List<T> like this: public class TransferFileList<T>
I have a DataGridView with its datasource set to a generic list of custom
I have a generic list of objects in C#, and wish to clone the
I have a generic list of objects in C#, for example sake, here's what
Can anyone help.. I have a generic list like so IList<itemTp> itemTps; itemTp basically
I have created a subclass of a generic list so that I could implement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.