summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Petit <kevin.petit@outlook.com>2017-01-19 10:12:51 +0100
committerStephane Delcroix <stephane@delcroix.org>2017-01-19 10:12:51 +0100
commita11e4c638b105c4d6466894c57a357c893996116 (patch)
tree35161c7edb7501118ec7b92c173e69e9ca2ee0f9
parentfb024a6e62363af2b14e704c0559eb7a2f08c082 (diff)
downloadxamarin-forms-a11e4c638b105c4d6466894c57a357c893996116.tar.gz
xamarin-forms-a11e4c638b105c4d6466894c57a357c893996116.tar.bz2
xamarin-forms-a11e4c638b105c4d6466894c57a357c893996116.zip
Fix NullReferenceException in VisualElement finalize. (#701)
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla51503.cs80
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
-rw-r--r--Xamarin.Forms.Core/VisualElement.cs2
3 files changed, 82 insertions, 1 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla51503.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla51503.cs
new file mode 100644
index 00000000..e9cdebc9
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla51503.cs
@@ -0,0 +1,80 @@
+using System;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 51503, "NullReferenceException on VisualElement Finalize", PlatformAffected.All)]
+ public class Bugzilla51503 : TestNavigationPage
+ {
+ protected override void Init()
+ {
+ PushAsync(new RootPage());
+ }
+
+ [Preserve(AllMembers = true)]
+ class RootPage : ContentPage
+ {
+ public RootPage()
+ {
+ Button button = new Button
+ {
+ AutomationId = "Button",
+ Text = "Open"
+ };
+
+ button.Clicked += Button_Clicked;
+
+ Content = button;
+ }
+
+ async void Button_Clicked(object sender, EventArgs e)
+ {
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+
+ await Navigation.PushAsync(new ChildPage());
+ }
+ }
+
+ [Preserve(AllMembers = true)]
+ class ChildPage : ContentPage
+ {
+ public ChildPage()
+ {
+ Content = new Label
+ {
+ AutomationId = "VisualElement",
+ Text = "Navigate 3 times to this page",
+ Triggers =
+ {
+ new EventTrigger()
+ }
+ };
+ }
+ }
+
+#if UITEST
+[Test]
+ public void Issue51503Test()
+ {
+ for (int i = 0; i < 3; i++)
+ {
+ RunningApp.WaitForElement(q => q.Marked("Button"));
+
+ RunningApp.Tap(q => q.Marked("Button"));
+
+ RunningApp.WaitForElement(q => q.Marked("VisualElement"));
+
+ RunningApp.Back();
+ }
+ }
+#endif
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index e040a049..ba7de6cb 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -222,6 +222,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla28650.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla37431.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla44777.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla51503.cs" />
<Compile Include="$(MSBuildThisFileDirectory)_Template.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1028.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1075.cs" />
diff --git a/Xamarin.Forms.Core/VisualElement.cs b/Xamarin.Forms.Core/VisualElement.cs
index cff1eb10..352e2549 100644
--- a/Xamarin.Forms.Core/VisualElement.cs
+++ b/Xamarin.Forms.Core/VisualElement.cs
@@ -790,7 +790,7 @@ namespace Xamarin.Forms
}
if (!GetIsDefault(TriggersProperty)) {
- var triggers = GetValue(TriggersProperty) as AttachedCollection<Trigger>;
+ var triggers = GetValue(TriggersProperty) as AttachedCollection<TriggerBase>;
triggers.DetachFrom(this);
}
}