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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:12:39+00:00 2026-05-31T18:12:39+00:00

I had a strange bug i don’t understand, and changing LINQ’s IEnumerable to list

  • 0

I had a strange bug i don’t understand, and changing LINQ’s IEnumerable to list half way through fixed it, and i dont understand why

Not Real the Code, but very similar
The code below doesn’t work:

// an IEnumerable of some object (Clasess) internally an array
var ansestors = GetAnsestors();

            var current = GetCurrentServerNode();

            var result = from serverNode in ansestors
                         select new PolicyResult
                                    {
                                      //Some irrelevant stuff 
                                        OnNotAvailableNode = NodeProcessingActionEnum.ContinueExecution,
                                    };

            var thisNode = new PolicyResult
            {
                //Some irrelevant stuff 
                OnNotAvailableNode = NodeProcessingActionEnum.ThrowException,
            };

            result = result.Reverse();
            result = result.Concat(new List<PolicyResult> { thisNode });

            result.First().OnNotAvailableNode = NodeProcessingActionEnum.ThrowException;

            // When looking in the debugger, and in logs, the first element of the
            // result sequence has OnNotAvailableNode set to ContinueExecution
            // Which doesnt make any sense...

But when i change the ending to the following it works:

        result = result.Reverse();
        result = result.Concat(new List<PolicyResult> { thisNode });

        var policyResults = result.ToList();
        var firstPolicyResult = policyResults.First();

        firstPolicyResult.OnNotAvailableNode = NodeProcessingActionEnum.ThrowException;
        return policyResults;

All the types here are classes (reference types) except NodeProcessingActionEnum which is an enum.

Is this a bug?

Me missing something crucial about LINQ?

Help?

  • 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. Editorial Team
    Editorial Team
    2026-05-31T18:12:40+00:00Added an answer on May 31, 2026 at 6:12 pm

    result.First() executes the (deferred / lazy) query.

    That line will set the value OK but when you use result later the query will be executed again.

    Later you are looking at a newly fetched copy. The fact that it is different lets me assume that GetAnsestors() is also lazily evaluated and is not an in memory List<>

    This means that ToList() is a worthwhile optimization as well as a fix. Note that after the ToList you can also use

     var firstPolicyResult = policyResults[0];  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a strange bug when porting a feature to the Python 3.1 fork
I was working on a program today and hit this strange bug. I had
I'm having fun with dates in flex, and had a strange bug showing up.
We had a strange bug report from a user who has iOS 4.2.1 on
We had discovered strange behaviour of popups in IE8. In IE7 and IE6 our
I know it is a strange question did someone have had a case where
I switched from Visual Studio to Code::Blocks yesterday, and just had some strange compiler
I have a strange bug where I am doing an ajax load from an
I just had some very strange behavior with a simple php script I was
I've got a strange bug I'm not sure how to track down. I'm running

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.