-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] CarouselView: VirtualView cannot be null here, when clearing and adding items on second navigation #22035
Comments
I just updated the repro project to 8.0.21 SR 4.1 and confirmed the bug still exists there. |
Verified this issue with Visual Studio 17.10.0 Preview 5(8.0.21&8.0.20&8.0.14&8.0.10&8.0.7&8.0.40-nightly.10515+sha.d6a3c50c93-azdo.9437127). Can repro on android platform with sample project. |
I concur, this is happening in my carouselview. Please fix. |
+1 |
Can you test with the latest nightly build? |
I will test |
@PureWeen Unfortunately, with the latest nightly 8.0.40-nightly.10602, this bug is still present in the repro project. Did a full clean and build. See below. carousel_virtualview_error_8.0.40-nightly.10602.mp4 |
If you make Page2 Transient instead of scoped does that fix it? https://github.com/RedZone908/CarouselVirtualViewErrorRepro/blob/master/MauiProgram.cs#L18 |
@PureWeen that takes away the error, but, it also makes the CarouselView start over with zero items at each page load (which makes sense, since the page is being recreated), so it's still not technically a return to the 8.0.3 behavior where the carousel items could be retained between page loads before adding/deleting any other items. |
can you make the viewmodel and data survive longer than the scope of the page? to be clear I'm not saying this isn't a bug :-) Just proposing some workarounds for now |
Ah, gotcha! Well, for the actual proprietary company app where we encountered this bug, we actually didn't need to retain the data so our workaround was to simply instantiate a new ObservableCollection on every page load, and that did take away the error. So this particular bug definitely isn't a blocker for the product I support at this stage. It'd be nice if we didn't have to do it, sure, but it IS an easy one-line workaround, basically: public override void OnAppearing()
{
this.MyListOfThings = new ObservableCollection() { /*your data here */ };
// can also call a method on your viewModel to do this -- just showing as OnAppearing to keep the example simple
} I was merely pointing out the "can't retain data" piece because at this point, I was thinking beyond the scope of my application and to the broader implications of the bug itself. But yeah, on Monday I can give the repro project a longer-lived dataset. If that works, then that also would be a viable workaround for others. |
…g and adding items on second navigation - fix (#22207) * Fix #22035 * Added UITest * Updated test * Updated test * Updated test * Updated test * - small change to code and fix test * Update Issue22035.cs * Update Issue22035.cs * - fix test * - fix test --------- Co-authored-by: Javier Suárez <javiersuarezruiz@hotmail.com> Co-authored-by: Shane Neuville <shneuvil@microsoft.com> Co-authored-by: Shane Neuville <shane94@hotmail.com>
Description
In Android only, starting from Maui 8.0.6 SR1 and continues to at least 8.0.20 SR4 (
might be in 8.0.21 SR4.1 but haven't tested that oneEDIT: it is still in 8.0.21 SR4.1), an exception occurs when adding items to the ObservableCollection backing a CarouselView after having navigated to the same page for a second time. This is very similar to what used to happen to Collection Views in .NET 7 as chronicled in #12219 (and fixed in #13385), except now it happens for CarouselViews. Case-in-point, my repro project is merely an updated and modified version of jaldinger's repro project from back in that issue, and it manifests the same behavior for CarouselViews now as it did for CollectionViews back then (I have verified that CollectionViews do not experience this issue anymore, so the previous bugfix hasn't been regressed).carousel_virtualview_error.mp4
Occurs in 8.0.21 SR 4.1, 8.0.20 SR4, 8.0.14 SR3.1, 8.0.10 SR3, 8.0.7 SR2,
Might be in the newest 8.0.21 SR 4.1 but haven't tested that one yet since it just came out hours ago.It is tested nowSteps to Reproduce
**System.InvalidOperationException:** 'VirtualView cannot be null here'
Link to public reproduction project repository
https://github.com/RedZone908/CarouselVirtualViewErrorRepro/tree/master
Version with bug
8.0.6 SR1
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
8.0.3 GA
Affected platforms
Android
Affected platform versions
Android 21 and up
Did you find any workaround?
Simply instantiating a new
ObservableCollection
in the page'sOnAppearing
handler instead of reusing the existing one will not trigger the error.Relevant log output
The text was updated successfully, but these errors were encountered: