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 70795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:47:13+00:00 2026-05-10T19:47:13+00:00

Some background info; LanguageResource is the base class LanguageTranslatorResource and LanguageEditorResource inherit from LanguageResource

  • 0

Some background info;

  • LanguageResource is the base class
  • LanguageTranslatorResource and LanguageEditorResource inherit from LanguageResource
  • LanguageEditorResource defines an IsDirty property
  • LanguageResourceCollection is a collection of LanguageResource
  • LanguageResourceCollection internally holds LanguageResources in Dictionary<string, LanguageResource> _dict
  • LanguageResourceCollection.GetEnumerator() returns _dict.Values.GetEnumerator()

I have a LanguageResourceCollection _resources that contains only LanguageEditorResource objects and want to use LINQ to enumerate those that are dirty so I have tried the following. My specific questions are in bold.

  1. _resources.Where(r => (r as LanguageEditorResource).IsDirty)

    neither Where not other LINQ methods are displayed by Intellisense but I code it anyway and am told ‘LanguageResourceCollection does not contain a definition for ‘Where’ and no extension method…’.

    Why does the way that LanguageResourceCollection implements IEnumerable preclude it from supporting LINQ?

  2. If I change the query to

    (_resources as IEnumerable<LanguageEditorResource>).Where(r => r.IsDirty)

    Intellisense displays the LINQ methods and the solution compiles. But at runtime I get an ArgumentNullException ‘Value cannot be null. Parameter name: source’.

    Is this a problem in my LINQ code?
    Is it a problem with the general design of the classes?
    How can I dig into what LINQ generates to try and see what the problem is?

My aim with this question is not to get a solution for the specific problem, as I will have to solve it now using other (non LINQ) means, but rather to try and improve my understanding of LINQ and learn how I can improve the design of my classes to work better with LINQ.

  • 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-10T19:47:14+00:00Added an answer on May 10, 2026 at 7:47 pm

    It sounds like your collection implements IEnumerable, not IEnumerable<T>, hence you need:

    _resources.Cast<LanguageEditorResource>().Where(r => r.IsDirty) 

    Note that Enumerable.Where is defined on IEnumerable<T>, not IEnumerable – if you have the non-generic type, you need to use Cast<T> (or OfType<T>) to get the right type. The difference being that Cast<T> will throw an exception if it finds something that isn’t a T, where-as OfType<T> simply ignores anything that isn’t a T. Since you’ve stated that your collection only contains LanguageEditorResource, it is reasonable to check that assumption using Cast<T>, rather than silently drop data.

    Check also that you have ‘using System.Linq’ (and are referencing System.Core (.NET 3.5; else LINQBridge with .NET 2.0) to get the Where extension method(s).

    Actually, it would be worth having your collection implement IEnumerable<LanguageResource> – which you could do quite simply using either the Cast<T> method, or an iterator block (yield return).

    [edit] To build on Richard Poole’s note – you could write your own generic container here, presumably with T : LanguageResource (and using that T in the Dictionary<string,T>, and implementing IEnumerable<T> or ICollection<T>). Just a thought.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone give me some info/background info on how I might go about writing
Some Background to begin: I've implemented a custom MembershipProvider that validates a user from
Some Background info: My web application stores some XML in a Text column of
Here's some background info. I have three MySQL tables (all InnoDB). The first table
Hey everyone, some background info: In the config file for my website, I set
Some background info I am programming in a system that uses a proprietary programming
Some background info: I am working on an opengl game for fun/experience, and in
heres some background info: I want to make a menu where clicking on a
First, some background info: I am making a compiler for a school project. It
I am having issues of having an image change dynamically. Some background info: I

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.