Bug 57060 - ResourceDictionary broken when compiling with .NET native toolchain
Summary: ResourceDictionary broken when compiling with .NET native toolchain
Status: RESOLVED DUPLICATE of bug 56795
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.4
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Stephane Delcroix
Depends on:
Reported: 2017-06-01 15:33 UTC by Matthew Richardson
Modified: 2017-06-06 11:09 UTC (History)
5 users (show)

Is this bug a regression?: Yes
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 Matthew Richardson 2017-06-01 15:33:29 UTC
PR #536 "ResourceDictionary fixes" was added in XF 2.3.4, but this now breaks under .NET native compilation.
The result? You get an empty ResourceDictionary and no XAML styles are applied in the compiled application.

Xamarin.Forms.Core/ResourceDictionary.cs, Line 30
_mergedInstance = s_instances.GetValue(_mergedWith,(key) => (ResourceDictionary)Activator.CreateInstance(key));

Activator.CreateInstance won't work with .NET native toolchain compilation.

See comment below on MSDN page ".NET Native and Compilation"

"Because the .NET Native tool chain links implementation code into your app only if it knows that your app actually invokes that code, either the metadata or the implementation code required in the following scenarios may not be included with your app: Reflection, Dynamic or late-bound invocation."

This is a critical issue, as it means you can't .NET native compile a XF 2.3.4 app on UWP.
Can a fix for this please be prioritised quickly?
Comment 2 Matthew Richardson 2017-06-02 10:57:40 UTC
Thanks Paul.

We're trying to nail down a simple repro project for this. It appears that the problem doesn't happen under all instances, we are trying to trace it by enabling .NET Native static analysis and looking through any warnings generated.

Simple resource dictionaries don't always reproduce the problem. It is very odd. Also looking at whether it may be related to XAMLC. Once we pin it down, will post the repro  project here.
Comment 3 Matthew Richardson 2017-06-02 19:38:23 UTC
OK, we have followed this through today and have found the issue is not with the ResourceDictionary but XAMLC and/or DataTriggers. We traced through a .NET native build in debug mode and found resource keys were being pulled OK, but not applied.

Applying the workaround here resolves the issue.

Therefore the description of this bug report is not entirely accurate after further investigation, but the root cause appears related to #56795. ResourceDictionary is not empty, but rather the resulting XAML styles are simply not applied.
Comment 4 Stephane Delcroix 2017-06-06 11:09:57 UTC

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