Bug 59946 - Xamarin Forms Delegate through method NullReferenceException
Summary: Xamarin Forms Delegate through method NullReferenceException
Alias: None
Product: Live Player
Classification: Xamarin
Component: Mobile App Android (show other bugs)
Version: 1.0.507
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-10-04 10:04 UTC by Timothy Lutt
Modified: 2017-11-16 08:51 UTC (History)
2 users (show)

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


Description Timothy Lutt 2017-10-04 10:04:05 UTC
A VisualizationError NullReferenceException is thrown in the app when a delegate is passed through a method parameter. Works fine in emulator.

#Steps to reproduce:
1. Create a Shared Xamarin Forms project
2. In the MainPage constructor add:
   DataController dataController = DataController.GetInstance(onDatabaseReady_FillAndGet);
3. Set a breakpoint on the line you just added
4. Add a method to the MainPage class:
   private void onDatabaseReady_FillAndGet()
5. In a new DataController.cs class 
    class DataController
        public delegate void OnDatabaseReady();

        private static DataController instance;

        // Privately hide the constructor
        private DataController(OnDatabaseReady callback = null)

        // The static function to get an instance of the datacontroller
        public static DataController GetInstance(OnDatabaseReady callback = null)
            return DataController.instance ?? (instance = new DataController(callback));
6. Run the app in Live Previewer
7. After the breakpoint is reached, use any of the step functions and the error will occur

#Expected result:
The GetInstance static method will be called without erroring

#Actual Result:
A VisualizationError NullReferenceException is thrown in the app
Comment 1 Timothy Lutt 2017-10-05 08:52:55 UTC
Tested on:
- OnePlus 3 A3003
- Samsung Note 4 SM-N910F
Comment 2 James Montemagno [MSFT] 2017-11-16 08:51:19 UTC
Please signup for test flight version: https://aka.ms/liveplayeralpha

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