Hi team,
when using an HttpClient and set Multiple selection property true and AllowVirtualization [RadzenListBox],
throws an hard exception.
Error: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.List1.Enumerator.MoveNext()* *at System.Linq.Enumerable.SelectListIterator
2.MoveNext()
at System.Linq.Enumerable.CastIterator[TResult](IEnumerable source)+MoveNext()
*at Radzen.DropDownBase`1.SelectItemFromValue(Object value) *
in ...\radzen-blazor\Radzen.Blazor\DropDownBase.cs:line 950
It tries to change the list in the same time as the list is read.
A quick fix would be to copy the list.
//Change from
foreach (object v in values)
//To
foreach (object v in values.ToList())
The method name is "SelectItemFromValue(object value)" in "DropDownBase" class
But this is not a clean solution.
I unfortunately do not have time for a clean solution and pull request
I hope the bug can be fixed quickly.
As an example:
<h4>Virtualization using LoadData event</h4>
<RadzenListBox AllowVirtualization="true"
Multiple="true"
AllowFiltering="true"
Count="@count"
LoadData=@LoadDataVirtualization
Data=@attributesDataVirtualization
TextProperty="Name"
ValueProperty="Name"
@bind-Value=@attributeValues
Style="height:200px" Class="w-100" />
IEnumerable<string> attributeValues = new string[] { };
async Task LoadDataVirtualization(LoadDataArgs args)
{
var pagedResult = await GetAttributesAsync(args.Skip.HasValue ? args.Skip.Value : 0, args.Top.HasValue ? args.Top.Value : 10);
count = items.Count;
attributesDataVirtualization = pagedResult.Results;
//var query = dbContext.Customers.AsQueryable();
//if (!string.IsNullOrEmpty(args.Filter))
//{
// query = query.Where(c => c.CustomerID.ToLower().Contains(args.Filter.ToLower()) || c.ContactName.ToLower().Contains(args.Filter.ToLower()));
//}
//console.Log($"LoadData with virtualization: Skip:{args.Skip}, Top:{args.Top}, Filter:{args.Filter}");
//count = query.Count();
//customCustomersDataVirtualization = query.Skip(args.Skip.HasValue ? args.Skip.Value : 0).Take(args.Top.HasValue ? args.Top.Value : 10).ToList();
//InvokeAsync(StateHasChanged);
}
I have tested this directly in the Radzen demo (repo)
@Parijsy
There is probably a similar problem but I am not sure
RadzenListBox with Multiple and Virtualization
-Tom