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 ()
Version: 1.0.507
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-10-04 10:04 UTC by n/a
Modified: 2017-11-16 08:51 UTC (History)
2 users (show)

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

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 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:

Description n/a 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 n/a 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