Bug 53513 - Windows Phone 8.1 - xaml silently not loaded
Summary: Windows Phone 8.1 - xaml silently not loaded
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 2.3.3
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jason Smith [MSFT]
Depends on:
Reported: 2017-03-20 09:19 UTC by Milan Laslop
Modified: 2017-07-03 05:36 UTC (History)
2 users (show)

Tags: crash, wp81, xaml, ac
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:

Description Milan Laslop 2017-03-20 09:19:31 UTC
Happens with Xamarin Forms versions starting with - these were explicitly tested:,,,
Does not happen with Xamarin Forms versions before - these were explicitly tested:

Before chaning Xamarin Forms version using NuGet, do "git clean -fdx" (to avoid any bin/obj leftovers).

Happens on any real device - explicitly tested: Nokia Lumia 930, Microsoft Lumia 650.
Does not happen on emulators.

Minimal project reproducing the issue: https://github.com/milan11/xamarin_forms_xaml_test
See project App2 (Porable), file MainPage.xaml. Any of the 3 marked elements cause that the Xaml is not loaded - the application crashes on NullReferenceException on line: label1.Text = "abc"; (because label1 is not bound)
Commenting out all the marked elements avoids the problem - app is loaded correctly.
Comment 1 Milan Laslop 2017-03-20 09:35:14 UTC
After seeing maybe related bug https://bugzilla.xamarin.com/show_bug.cgi?id=53051 I tried to add
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
to Portable (Xamarin Forms) project's AssemblyInfo.cs, and then it always works correctly.
So, I am not sure if this is a bug or not.
Comment 2 Jimmy [MSFT] 2017-03-22 15:31:44 UTC
Thank you for filing this report!

I ran the project you provided in the description and was able to reproduce this issue on a device. The app would crash at launch with the exception message:

> "System.Exception: Failed to create initial page\r\n   at App2.Win.App.OnLaunched(LaunchActivatedEventArgs e)"	string

debug output: https://gist.github.com/jimmgarrido/af0f891971b4c7c27df5c114ed09504d

As mentioned in comment 1, enabling XamlC does appear to resolve the issue. Also, this issue does _not_ occur when creating pages with code instead of xaml. However I am still confirming this report so the team can investigate further and provide more info.
Comment 3 Jason Smith [MSFT] 2017-06-19 20:48:19 UTC
Please use XamlC for Windows 8.1. If you are still seeing this issue with UWP (I am unable to reproduce using the UWP backend) please re-open.
Comment 4 Milan Laslop 2017-07-03 05:36:31 UTC
This issue was seen only on 8.1. On UWP it does not happen.
However, the found workaround (enabling XamlC) causes another problems:

1. It fails static code analysis:
When compiling using msbuild with /p:RunCodeAnalysis=true:
MSBUILD : error : CA0001 : An error was encountered while parsing IL for method: 'XProject.YPage.InitializeComponent', instruction at offset '0x933' with opcode 'Callvirt'.

2. Building of the solution in Xamarin Studio (tried version 6.3 (build 864) on MAC) fails:

There is the error "Object reference not set to an instance of an object" for all xaml files in the project.

In another part of log, there is:
Parsing Xaml... done.
Replacing YPage.InitializeComponent ()... failed.

This unnecessarily complicates the solution configuration, since some projects have to be built with XamlC enabled and some (e.g. those we want to be compilable on MAC) with XamlC disabled.

Since this problem did not happen with Xamarin Forms versions before, I believe that it is possible for this bug to be really fixed (instead of using that XamlC workaround).