This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 51503 - NullReferenceException and crash on VisualElement finalization.
Summary: NullReferenceException and crash on VisualElement finalization.
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
: 51685 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-01-13 12:21 UTC by Kevin Petit
Modified: 2017-03-08 18:45 UTC (History)
7 users (show)

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


Attachments

Description Kevin Petit 2017-01-13 12:21:29 UTC
I downloaded the latest Xamarin preview 2.3.4.184-pre1.

My application randomly crash after navigating.

The only log I have before the crash is this :
Unhandled error System.NullReferenceException: Object reference not set to an instance of an object at Xamarin.Forms.VisualElement.Finalize ()

So I think the bug is introduced by this pull request : https://github.com/xamarin/Xamarin.Forms/pull/555.
Comment 1 Aleksandr Malets 2017-01-17 09:35:11 UTC
I have the same bug
Xamarin preview 2.3.4.184-pre1.

Xamarin Studio Community
Version 6.1.2 (build 44)
Installation UUID: ba7ca403-d4fd-4c96-bf60-5e311ad48a72
Runtime:
	Mono 4.6.2 (mono-4.6.0-branch/08fd525) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406020007

NuGet
Version: 3.4.3.0

Xamarin.Profiler
Not Installed

Apple Developer Tools
Xcode 8.2.1 (11766.1)
Build 8C1002

Xamarin.Android
Version: 7.0.2.37 (Xamarin Studio Community)
Android SDK: /Users/softhememac/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.4   (API level 19)
		5.0   (API level 21)
		6.0   (API level 23)
		7.0   (API level 24)

SDK Tools Version: 25.2.2
SDK Platform Tools Version: 25
SDK Build Tools Version: 25

Java SDK: /usr
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Xamarin Android Player
Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

Xamarin.iOS
Version: 10.3.0.0 (Xamarin Studio Community)
Hash: e02d272
Branch: xcode8.2
Build date: 2016-12-12 23:00:41-0500

Xamarin.Mac
Version: 2.10.0.113 (Xamarin Studio Community)

Xamarin Inspector
Version: 1.0.0.0
Hash: 1f3067d
Branch: master
Build date: 11/15/2016 11:13:59 PM

Build Information
Release ID: 601020044
Git revision: 0ccfcd52b95305ebd5b7eca0d88c1017035910ae
Build date: 2016-10-28 15:12:43-04
Xamarin addins: a39a869d8a78d87bdc6775f696c13a4cc9024501
Build lane: monodevelop-lion-cycle8

Operating System
Mac OS X 10.12.2
Darwin Alexs-MacBook-Pro.local 16.3.0 Darwin Kernel Version 16.3.0
    Thu Nov 17 20:23:58 PST 2016
    root:xnu-3789.31.2~1/RELEASE_X86_64 x86_64

Enabled user installed addins
NuGet Package Explorer 0.1
SSH Debugger 0.4
Xamarin Inspector 1.0.0.0
XamlStyler 1.0.3
Comment 2 Antonio Ibarra 2017-01-17 13:48:12 UTC
I have the same problem,

In file VisualElement.cs
Line 793:
var triggers = GetValue(TriggersProperty) as AttachedCollection<Trigger>

Should be changed to
var triggers = GetValue(TriggersProperty) as AttachedCollection<TriggerBase>

?
Comment 3 Rex Hiebert 2017-01-17 19:19:04 UTC
I have almost exactly the same thing:

Unhandled Exception:
[mono] System.NullReferenceException: Object reference not set to an instance of an object.
[mono]   at Xamarin.Forms.VisualElement.Finalize () [0x00040] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:794 
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.
[mono-rt]   at Xamarin.Forms.VisualElement.Finalize () [0x00040] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:794

Which is referencing this section of code in VisualElement.cs
if (!GetIsDefault(TriggersProperty)) {
   var triggers = GetValue(TriggersProperty) as AttachedCollection<Trigger>;
   triggers.DetachFrom(this);
}


line 794 is the "triggers.DetachFrom(this)" it looks like "triggers" needs a null reference check
Comment 4 Stephane Delcroix 2017-01-19 09:20:50 UTC
https://github.com/xamarin/Xamarin.Forms/pull/701 has been merged.

the fix will be part of 2.3.4-pre2
Comment 5 Jimmy Garrido 2017-03-08 18:45:29 UTC
*** Bug 51685 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.