maui: SwipeView throw exception on windows
Description
it seems following combintions triggers program to throw an exception of “Value does not fall within the expected range.”:
- CollectioView with SwipeView
- the binding list of collectionview is initiazed with some items
- then clear the list, and add a new item
I have created a simple example to reproduce: https://github.com/hujun-open/mauiswieviewissue
I only found this issue on windows, android works fine.
following are the visual studio version info:
Microsoft Visual Studio Community 2022
Version 17.3.0 Preview 4.0
VisualStudio.17.Preview/17.3.0-pre.4.0+32714.290
Microsoft .NET Framework
Version 4.8.04084
Installed Version: Community
ASP.NET and Web Tools 17.3.372.35679
ASP.NET and Web Tools
Azure App Service Tools v3.0.0 17.3.372.35679
Azure App Service Tools v3.0.0
C# Tools 4.3.0-3.22329.30+29e657c0582904529bae2a87c227220e03f509cf
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
Extensibility Message Bus 1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Mono Debugging for Visual Studio 17.3.20 (3f4cb00)
Support for debugging Mono processes with Visual Studio.
NuGet Package Manager 6.3.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/
Razor (ASP.NET Core) 17.0.0.2232702+e1d654e792aa2fe6646a6935bcca80ff0aff4387
Provides languages services for ASP.NET Core Razor.
TypeScript Tools 17.0.10701.2001
TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 4.3.0-3.22329.30+29e657c0582904529bae2a87c227220e03f509cf
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual F# Tools 17.1.0-beta.22327.2+ddc90b20287a765a9d526da42b3be0dd8e907ec5
Microsoft Visual F# Tools
Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.
VisualStudio.DeviceLog 1.0
Information about my package
VisualStudio.Mac 1.0
Mac Extension for Visual Studio
VSPackage Extension 1.0
VSPackage Visual Studio Extension Detailed Info
Xamarin 17.3.0.288 (main@5d42bb2)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin Designer 17.3.0.204 (remotes/origin/d17-3@f5da0100a)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
Xamarin.Android SDK 13.0.0.0 (d17-3/030cd63)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: dffa5ab
Java.Interop: xamarin/java.interop/d17-3@7716ae53
SQLite: xamarin/sqlite/3.38.5@df4deab
Xamarin.Android Tools: xamarin/xamarin-android-tools/main@14076a6
Steps to Reproduce
see readme @ https://github.com/hujun-open/mauiswieviewissue
Version with bug
6.0.400
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
windows 10 Enterprise 21H2, OS build 19044.1826
Did you find any workaround?
no
Relevant log output
+ sender {SwipeIssueDemo.WinUI.App} object {SwipeIssueDemo.WinUI.App}
- e {Microsoft.UI.Xaml.UnhandledExceptionEventArgs} Microsoft.UI.Xaml.UnhandledExceptionEventArgs
- Exception {"Value does not fall within the expected range."} System.Exception {System.ArgumentException}
+ Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
HResult -2147024809 int
HelpLink null string
+ InnerException null System.Exception
Message "Value does not fall within the expected range." string
ParamName null string
Source null string
StackTrace null string
TargetSite null System.Reflection.MethodBase
+ Static members
+ Non-Public members
Handled false bool
Message "The parameter is incorrect.\r\n" string
+ Non-Public members
Depends on
VS bug #1870771
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 4
- Comments: 29 (4 by maintainers)
Commits related to this issue
- NR: Remove SwipeView as it is responsible for a crash on the Windows platform. See https://github.com/dotnet/maui/issues/8870 — committed to jbe2277/waf by jbe2277 a year ago
I just ran into the same problem with Visual Studio 17.4.5 and MAUI 7.0.59 in a demo project I’m developing for a conference where I’ll be talking about .NET MAUI and wanted to share my workaround.
I was able to get around the issue by migrating my XAML code to C# markup using the helper methods from the [.NET MAUI Community Toolkit] (https://learn.microsoft.com/de-de/dotnet/communitytoolkit/maui/markup/markup). Within the C# markup file, I was able to use conditional compilation to exclude the SwipeView on Windows.
See:
https://github.com/AndreKraemer/basta-2023-se-maui-demo/blob/fb33963810b7788795fcf6445d4d5f4cf256e26b/ConferenceMauiDemo/Views/SessionsPageMarkup.cs#L152
Since the
SwipeViewdoesn’t work on Windows when using the application with a mouse, it wasn’t a big deal to exclude it from my view. To give Windows users the same functionality that users of other platforms have with theSwipeView, I added a context menu (right click). See: https://github.com/AndreKraemer/basta-2023-se-maui-demo/blob/fb33963810b7788795fcf6445d4d5f4cf256e26b/ConferenceMauiDemo/Views/SessionsPageMarkup.cs#L238Since this was used to close at least #9540, #9423 and #8870 there seems to be a fair amount of interest. PR #11229 seems like it corrects this but says “The PR require some changes in the public API. Will maintain the changes up to date but need to wait to .NET 8.”
Fair enough, but if breaking changes are the problem at least put something in the community toolkit temporarily because waiting for .NET 8 to fix a bug in .NET 6 seems excessive.
I agree, I have a swipe view for use on mobile devices and am using context menus for desktop. At a minimum we need the presence of a swipe view in a collection view to at least not crash!
Absent a response from Microsoft I can only guess, but it looks like it’s being worked on. I noticed a while back that PR #11229 by @jsuarezruiz seems like it corrects this but says “The PR require some changes in the public API. Will maintain the changes up to date but need to wait to .NET 8.” That was in November of 2022, however it looks like a new decision has been reached and PR #11229 was closed at the beginning of July 2023 with “We are going to close this PR focusing on fix crashes or any problem that prevents the use of SwipeView in Windows while we continue to promote the implementations and accessibility on the desktop (keyboard support etc).”
A SwipeView without mouse support is not a very practical desktop UI element but as long as its presence does not crash the app (as it currently does in this example) it shouldn’t be too hard to code around that and offer an alternative desktop interface. Not hard, but tedious.
This issue still exists with Visual Studio 17.4.5 and MAUI 7.0.59.
How to reproduce:
MainPage.xamlwithMainPage.xaml.cswithInsert itemsbutton until the items do not fit in the view anymore and would need a scrollbar -> Exception occurs. See screen cast:Note: Remove the
SwipeViewfrom theDataTemplate. Then this error does not occur.I’m seeing a similar issue in my simple MAUI application with an ObservableCollection<string> inside a CollectionView. I can add items, but once I remove an item and then try to add another item I get the UnhandledException:
[Microsoft.UI.Xaml.UnhandledExceptionEventArgs] Exception = {"Value does not fall within the expected range."} Message = {"The parameter is incorrect."}I also have defensive code in each add/remove method to make sure the collection is not null and the item has content before removing or adding.