I ran into an issue where my Xamarin.Forms UWP app, which uses MvvmCross and SyncFusion SfCharts stopped showing charts once I created the app package for the Windows Store (i.e. created *.appxupload package with .NET native tool chain).
I went hunting for a fix and rather quickly found a post on the SyncFusion official support forum about that problem. I also found that there’s a official Knowledge Base article:
Both saying the same thing, that one should go to their App.xaml.cs file and add an extra assembly (i.e. typeof(Syncfusion.SfChart.XForms.UWP.SfChartRenderer).GetTypeInfo().Assembly)
to their Xamarin.Forms.Init() parameter in the OnLaunched() method. Basically add this code:
var assembliesToInclude = new List<Assembly>();
Xamarin.Forms.Forms.Init(e , assembliesToInclude);
Unfortunately, this doesn’t work with MvvmCross 6.1.2 (probably doesn’t work with 6.2.0 as well – haven’t checked though). The charts are still not showing, even though the SfCharts assembly got included.
I can’t be 100% sure of the reason behind this problem but I suspect it’s because of the fact, that MvvmCross framework is now handling the Xamarin.Forms initialization for you. Because of that the Xamarin.Forms.Init() method is called multiple times – once in the App.xaml.cs and once inside of the framework. Another assumption, based on the results we’re seeing, is that Xamarin.Forms.Init() works in a way that the last in is the one that gets served – meaning that if the App.xaml.cs call happens before the MvvmCross one, then the SfChart assembly is not going to be included and Native tool chain compilation will strip it out.
A bit more explanation on this: Mvx framework calls the Xamarin.Forms.Init() method inside of the base Setup file – MvxFormsWindowsSetup calling Xamarin.Forms.Init(). The remedy is simple, move the code from App.xaml.cs to the GetViewAssemblies() override in your Setup.cs file. The GetViewAssemblies() method is being called at the launch of the app by MvvmCross and it is designed to retrieve additional assemblies to pass as a parameter into the Xamarin.Forms.Init() method – which is exactly what we want.
public class Setup : MvxFormsWindowsSetup<MvxApp, XamFormApp>
public override IEnumerable<Assembly> GetViewAssemblies()
var customAssemblies = new List<Assembly>()
That’s it – you should see your charts again!