score:4
Accepted answer
it could be that the collection is being modified at the same time as it is being iterated. if this code is accessed by more than one thread simultaneously, you might need to lock the list for modifications while iterating it.
score:1
locking during the tolist is not sufficient. you must also lock (the same object!) during the modification.
Source: stackoverflow.com
Related Query
- LINQ throwing invalid cast exception on a bigint
- LINQ Source Code Available
- List sum too large, throwing overflow exception
- Linq to SharePoint throwing null reference exception
- .NET 4 Code Contracts: "requires unproven: source != null"
- .ToList throwing exception
- .Except<T> is throwing an Exception
- Exception in System.Data.Entity.dll but was not handled in user code
- LINQ group by day of the week throwing exception
- creating Linq to sqlite dbml from DbLinq source code
- LINQ throwing Query nested too deeply exception
- Linq ThenBy() throwing "The best overloaded method match ThenBy() for has some invalid arguments" exception
- entity exception was unhandled by user code
- Using linq for validation/ throwing exception
- Nested LINQ Method throwing a `Not Supported...` Exception
- NHibernate LINQ Where and Any throwing exception
- Linq joins throwing exception
- An exception of type 'System.ArgumentException' occurred in EntityFramework.dll but was not handled in user code
- c# linq with group by and join throwing exception
- Entity Framework Code First ToList method timing out on SQL Azure
- Null reference exception in my LINQ to XML code
- C# Converting List throwing exception in linq query
- FirstOrDefault throwing exception instead of null
- Throwing exceptions from Linq Query exception
- source code for LINQ 101 samples
- Why Does ToList throw an Exception when only 1 record is returned
- Azure server throwing exception after certain numbers of API call
- Data Binding DataGridView to ComboBox Throwing Null Value Exception
- Trouble with a LINQ 'filter' code throwing an error
- LINQ Entity Framework query not working in EF Core, throwing exception
More Query from same tag
- Linq - Using GroupBy with my own type vs anonymous type
- FindIndex on list by linq
- Linq group by and count
- Exclude linq join condition based on parameter
- How to select from a List<string[]>
- Using Any to check against a list in NHibernate
- ParseXML how compare one attribute for take the value of the other in the same element
- Get Max Value of overlapping times in a list of Start and End Times
- Linq Result into Observable collection throws parsing exception
- LINQ Queries with dynamic Order By
- LINQ GroupBy anonymous type and select timestamp that is within +/- one minute
- Rename xml descendants
- Linq Aggregation Statement To Process Values Null and Not Null Values
- build poll system with Repeater control in asp.net
- How to do a nested count with OData and LINQ?
- Compare two Lists by specific properties
- LINQ sorting by number of appearances
- Object reference updating, update all collections property?
- LINQ swap columns into rows
- Remove XML node if the inner tag matches value using Linq in C#
- Getting null data when executing LINQ to Entities query
- Dynamically grouping by Day/Week/Month/Year at Runtime
- Order LINQ by "string" name
- calculate properties values depending on another property (LINQ)
- Casting an object inside join statement
- Return first item in list if FirstOrDefault returns null
- How can I update in Linq an entity that is disconnected from database?
- Clean the string? is there any better way of doing it?
- Is there best practice to obtain elements/variables from collection based on different conditions
- Cannot convert IQueryable<IEnumerable<string>> to return type IEnumerable<string>