Bug 29238 - [WinRT] Device.BeginInvokeOnMainThread throws NullReferenceException
Summary: [WinRT] Device.BeginInvokeOnMainThread throws NullReferenceException
Status: RESOLVED DUPLICATE of bug 29158
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.4.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-04-20 06:13 UTC by Michael Rumpler
Modified: 2015-04-20 12:48 UTC (History)
3 users (show)

Tags:
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 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 DUPLICATE of bug 29158

Description Michael Rumpler 2015-04-20 06:13:22 UTC
I'm using Xamarin.Forms.Windows.1.4.2.6353-pre2.

When I call Device.BeginInvokeOnMainThread on a background thread of a WinPhone 8.1 app, then a NullReferenceException is thrown.

The stack trace looks like this:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Xamarin.Forms.Platform.WinRT.WindowsBasePlatformServices.BeginInvokeOnMainThread(Action action)
   at Xamarin.Forms.Device.BeginInvokeOnMainThread(Action action)
   at MR.Gestures.GestureHandler.ExecuteCommand(ICommand command, Object parameter, BaseGestureEventArgs args)

And my code:

			try
			{
				if (command != null && command.CanExecute(parameter))
					Device.BeginInvokeOnMainThread(() => command.Execute(parameter));
			}
			catch(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine("Exception in ExecuteCommand:\n" + ex.ToString());
				throw ex;
			}

The same code works on the other platforms. It also works on WinPhone 8.1, if it is run in the main thread.

This bug has also been reported by Phil Russell in https://forums.xamarin.com/discussion/38167/xf-for-winphone8-1-rt-preview-begininvokeonmainthread-broken
Comment 1 Eric Maupin 2015-04-20 12:48:35 UTC

*** This bug has been marked as a duplicate of bug 29158 ***