Cysharp / Cysharp/ObservableCollections

SynchronizedViewList throws on ToList() / when used as IEnumerable

Open
#116 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
1k
Forks
73
Avg merge
5d 4h
Merged PRs (30d)
2

Description

When creating a ISynchronizedViewList (to have a simple list instead of mapping pairs) to ToList() method throws an exception on .ToList().
This only happens when there's actual items in the list.
This forces us to use the underlying ListView or its Filtered member with a Select() to actually copy or iterate the ViewList.
This makes the ViewList a very unreliable IEnumerable, prompting our team to actually never use it.

var sourceList = new ObservableList<int>();
var listView = sourceList.CreateView(x => x);

//Fill the list
sourceList.Add(42);

//This works
var listViewContents = listView.ToList();
var listViewContentsViaFiltered = listView.Filtered.Select(tuple => tuple.View).ToList();
//This throws
var listViewContentsViaViewList = listView.ToViewList().ToList();

Also see fiddle

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the ObservableList, CreateView, and ToViewList().ToList() example from the report, then trace the ToViewList() IEnumerable path for a populated view. Done means enumerating a populated ISynchronizedViewList and converting it with ToList() no longer throws, while the existing Filtered.Select path remains consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.