Bug 44953 - UWP: Pressing enter in an Entry in custom ViewCell causes Windows.UI.Xaml.UnhandledExceptionEventArgs
Summary: UWP: Pressing enter in an Entry in custom ViewCell causes Windows.UI.Xaml.Unh...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-09-30 19:25 UTC by fjordfnord
Modified: 2016-12-06 01:19 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Visual Studio project to reproduce the problem in this bug report (99.77 KB, application/x-gzip)
2016-09-30 19:25 UTC, fjordfnord
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description fjordfnord 2016-09-30 19:25:26 UTC
Created attachment 17831 [details]
Visual Studio project to reproduce the problem in this bug report

=== Overview ===

On UWP, using Xamarin.Forms, an Entry in custom ViewCell that is in a ListView will cause Windows.UI.Xaml.UnhandledExceptionEventArgs when enter is pressed in the Entry.

A tarball containing a reproducing project is attached.

=== Steps to Reproduce  ===

Using the attached project:
1. Focus any Entry in the main page list.
2. Press enter.

Or alternatively:
1. Create Xamarin.Forms UWP app.
2. Create a custom ViewCell containing an Entry.
3. Create Forms Page with ListView and TemplateSelector which uses the custom ViewCell.
4. Run the app, focus an Entry in the list, press enter.

=== Expected Behavior ===

Typing enter has no side-effects.

=== Actual Behavior ===

An exception occurs.

Callstack:
EntryApp.UWP.exe!EntryApp.UWP.App.InitializeComponent.AnonymousMethod__5_1(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e) Line 53	C#
[External Code]	
[Frames below may be incorrect and/or missing, no symbols loaded for Windows.UI.Xaml.dll]

Exception details:
-		e	{Windows.UI.Xaml.UnhandledExceptionEventArgs}	Windows.UI.Xaml.UnhandledExceptionEventArgs
-		Exception	{"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}	System.Exception {System.ArgumentOutOfRangeException}
		ActualValue	null	object
+		Data	{System.Collections.ListDictionaryInternal}	System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
		HResult	-2146233086	int
		HelpLink	null	string
+		InnerException	null	System.Exception
		Message	"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"	string
		ParamName	"index"	string
		Source	"mscorlib"	string
		StackTrace	"   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)\r\n   at System.Collections.Generic.List`1.get_Item(Int32 index)\r\n   at System.Collections.ObjectModel.Collection`1.System.Collections.IList.get_Item(Int32 index)\r\n   at Xamarin.Forms.ListProxy.<>c__DisplayClass35_1.<TryGetValue>b__0()\r\n   at Xamarin.Forms.ListProxy.TryGetValue(Int32 index, Object& value)\r\n   at Xamarin.Forms.ListProxy.get_Item(Int32 index)\r\n   at Xamarin.Forms.ListProxy.System.Collections.IList.get_Item(Int32 index)\r\n   at Xamarin.Forms.TemplatedItemsList`2.get_Item(Int32 index)\r\n   at Xamarin.Forms.ListView.NotifyRowTapped(Int32 groupIndex, Int32 inGroupIndex, Cell cell)\r\n   at Xamarin.Forms.ListView.NotifyRowTapped(Int32 index, Cell cell)\r\n   at Xamarin.Forms.ListView.Xamarin.Forms.IListViewController.NotifyRowTapped(Int32 index, Cell cell)\r\n   at Xamarin.Forms.Platform.UWP.ListViewRenderer.OnKeyPressed(Object sender, KeyRoutedEventArgs e)"	string
+		Static members		
+		Non-Public members		
		Handled	false	bool
		Message	"System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index\r\n   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)\r\n   at System.Collections.Generic.List`1.get_Item(Int32 index)\r\n   at System.Collections.ObjectModel.Collection`1.System.Collections.IList.get_Item(Int32 index)\r\n   at Xamarin.Forms.ListProxy.<>c__DisplayClass35_1.<TryGetValue>b__0()\r\n   at Xamarin.Fo"	string
+		Native View	0x11cf6838 <Information not available, no symbols loaded for Windows.UI.Xaml.dll>	IUnknown *

=== Visual Studio===

Microsoft Visual Studio Community 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01586

Installed Version: Community

Visual Basic 2015   00322-20000-00000-AA752
Microsoft Visual Basic 2015

Visual C# 2015   00322-20000-00000-AA752
Microsoft Visual C# 2015

Visual C++ 2015   00322-20000-00000-AA752
Microsoft Visual C++ 2015

Windows Phone SDK 8.0 - ENU   00322-20000-00000-AA752
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   7.8.00927.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2015.1   14.1.20810.0
ASP.NET and Web Tools 2015.1

ASP.NET Web Frameworks and Tools 2012.2   4.1.41102.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.40314.0
For additional information, visit http://www.asp.net/

AWS Toolkit for Visual Studio 2015   1.9.6.19
AWS Toolkit for Visual Studio 2015.
Copyright 2011-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.

This software includes third party software subject to the following copyrights:
- Logging from log4net, Apache License 
  [http://logging.apache.org/log4net/license.html]
- Putty for PPK to PEM conversion, MIT license 
  [http://www.chiark.greenend.org.uk/~sgtatham/putty/licence.html]
- NGit for AWS Elastic Beanstalk incremental push
  [https://github.com/mono/ngit/blob/master/NGit.license.txt]
- NSch dependency for NGit
  [https://github.com/mono/ngit/blob/master/NSch.license.txt]
- Sharpen dependency for NGit
  [https://github.com/mono/ngit/blob/master/Sharpen/AssemblyInfo.cs]
- ICSharpCode.SharpZipLib dependency for NGit
  [http://www.icsharpcode.net/opensource/sharpziplib/]
- Mono.Posix.dll and Mono.Security.dll dependencies for NGit
  [http://mono-project.com/FAQ:_Licensing#Licensing]
- MPFProj for Visual Studio Project Framework
  [http://mpfproj10.codeplex.com/license]
- JSON Checker for JSON validation
  [http://www.raboof.com/projects/jsonchecker/]

Azure App Service Tools v2.8.1   14.0.11123.0
Azure App Service Tools v2.8.1

Command Bus, Event Stream and Async Manager   Merq
Provides ICommandBus, IEventStream and IAsyncManager MEF services for loosely coupled Visual Studio extension components communication and integration.

Common Azure Tools   1.8
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

Microsoft .NET Core Tools (Preview 2)   14.1.20810.0
Microsoft .NET Core Tools (Preview 2)

Microsoft Azure Mobile Services Tools   1.4
Microsoft Azure Mobile Services Tools

NuGet Package Manager   3.5.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   14.0.60519.0
Microsoft SQL Server Data Tools

TypeScript   1.8.36.0
TypeScript tools for Visual Studio

Visual Studio Tools for Universal Windows Apps   14.0.25527.01
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

Xamarin   4.2.0.695 (7603786)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   7.0.1.2 (c1d1c79)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS   10.0.0.1 (29910bb)
Visual Studio extension to enable development for Xamarin.iOS.

=== Operating System ===

OS Name	Microsoft Windows 10 Home
Version	10.0.14393 Build 14393
Comment 1 c.krempp91 2016-10-17 14:23:55 UTC
I have found a very similar scenario with the Editor, the only difference is that the exception thrown is: System.ArgumentOutOfRangeException. Otherwise the same workflow and listview structure applies.
Comment 2 fjordfnord 2016-10-17 17:18:35 UTC
You most likely have the same problem. Exception System.ArgumentOutOfRangeException is present in the full stack trace.

The problem happens in Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs, where ListViewRenderer.OnKeyPressed calls OnListItemClicked with -1 as argument. In my custom compiled Xamarin.Forms I worked around this problem by just returning if List.SelectedIndex was -1.
Comment 3 c.krempp91 2016-10-17 22:06:47 UTC
You are correct, it is the same issue. We can not do a custom build of Xamarin Forms though, thus making this a urgent issue. 

From what I have gathered it seems like the OnKeyPressed functionality is an incomplete feature. By that I mean it seeks to select an item from the list, but because the selected item does not update (from the tab button, or by any other means) this leads to the identified issue. 

I think this feature should either be completed properly, or removed. If the feature is completed, I think that OnKeyPressed should be overrideable as well to allow for different key monitoring capabilities at the subclass level.
Comment 4 Paul DiPietro [MSFT] 2016-12-06 01:19:21 UTC
This looks to no longer be occurring on the latest stable (2.3.3), while it did crash with the first enter key press on the version provided with the reproduction provided. If you find that there's still an issue, please feel free to reopen this.