dotnet/maui · error · ArgumentNullException
Loop Manager expects a UICollectionViewFlowLayout
Error message
Loop Manager expects a UICollectionViewFlowLayout
What it means
CarouselViewLoopManager constructor throws ArgumentNullException when the UICollectionViewFlowLayout layout parameter is null. The loop manager implements infinite carousel scrolling and requires a valid flow layout to manage section insets, item spacing, and scroll positioning for the loop mechanism.
Source
Thrown at src/Compatibility/Core/src/iOS/CollectionView/CarouselViewController.cs:499
else
{
CollectionView.Hidden = true;
}
}
}
class CarouselViewLoopManager : IDisposable
{
int _indexOffset = 0;
UICollectionViewFlowLayout _layout;
const int LoopCount = 3;
ILoopItemsViewSource _itemsSource;
bool _disposed;
public CarouselViewLoopManager(UICollectionViewFlowLayout layout)
{
if (layout == null)
throw new ArgumentNullException(nameof(layout), "LoopManager expects a UICollectionViewFlowLayout");
_layout = layout;
}
public void CenterIfNeeded(UICollectionView collectionView, bool isHorizontal)
{
if (isHorizontal)
CenterHorizontalIfNeeded(collectionView);
else
CenterVerticallyIfNeeded(collectionView);
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{View on GitHub (pinned to f377ff1c5e)
Solutions
- Ensure a non-null UICollectionViewFlowLayout is created before constructing CarouselViewLoopManager
- Guard the constructor call: if (layout != null) _loopManager = new CarouselViewLoopManager(layout);
- Review CarouselViewController lifecycle to ensure layout exists before loop manager creation
- Dispose the loop manager before disposing the layout to prevent race conditions
Example fix
// before
_loopManager = new CarouselViewLoopManager(_layout); // throws if _layout was disposed
// after
if (_layout != null)
_loopManager = new CarouselViewLoopManager(_layout);
else
_loopManager = new CarouselViewLoopManager(new UICollectionViewFlowLayout()); Defensive patterns
Strategy: validation
Validate before calling
// Before constructing CarouselViewLoopManager, null-check the layout
if (layout == null)
throw new ArgumentNullException(nameof(layout), "UICollectionViewFlowLayout required");
var loopManager = new CarouselViewLoopManager(layout); Prevention
- Ensure UICollectionViewFlowLayout is created before the loop manager
- Dispose the loop manager before disposing the layout to prevent stale references
- Guard layout recreation in CarouselViewController lifecycle methods
When it happens
Trigger: Passing null to the CarouselViewLoopManager constructor; CarouselViewController creating the loop manager before the layout is initialized; layout disposed or nulled before loop manager construction during carousel teardown/recreation.
Common situations: CarouselView reconfiguration (e.g. changing layout direction) disposes the old layout before the loop manager is recreated; custom CarouselView setup that doesn't provide a flow layout; initialization race in the CarouselViewController lifecycle.
Related errors
- IItemsViewSource is empty
- renderer
- No test results found.
- No device was found to install the app on. See the Setup met
- UI Test application path not specified.
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/619c26b9dd81aa8d.
Report an issue: GitHub.