locked
In UWP project, how do we add assemblies in App.xaml.cs to compile with .net native toolchain? RRS feed

  • Question

  • User97031 posted

    Per the Troubleshooting section of https://developer.xamarin.com/guides/cross-platform/xamarin-forms/windows/getting-started/universal/, are we expected to track down every single .dll referenced by the PCL and UWP projects and add them one by one? If not, how do we discern assemblies that need to be added vs. those that do not?

    For Example (If i'm missing an assembly referenced by my PCL the app will crash on launch?):

         // you'll need to add `using System.Reflection;`
                List<Assembly> assembliesToInclude = new List<Assembly>();
    
                assembliesToInclude.Add(typeof(Xamarin.Insights).GetTypeInfo().Assembly);
                assembliesToInclude.Add(typeof(ImageCircle.Forms.Plugin.Abstractions.CircleImage).GetTypeInfo().Assembly);
                assembliesToInclude.Add(typeof(ImageCircle.Forms.Plugin.UWP.ImageCircleRenderer).GetTypeInfo().Assembly);
                assembliesToInclude.Add(typeof(ModernHttpClient.CaptiveNetworkException).GetTypeInfo().Assembly);
                assembliesToInclude.Add(typeof(Plugin.Connectivity.Abstractions.BaseConnectivity).GetTypeInfo().Assembly);
                assembliesToInclude.Add(typeof(Plugin.Connectivity.ConnectivityImplementation).GetTypeInfo().Assembly);
                assembliesToInclude.Add(typeof(Plugin.Settings.Abstractions.ISettings).GetTypeInfo().Assembly);
                assembliesToInclude.Add(typeof(Plugin.Settings.CrossSettings).GetTypeInfo().Assembly);
                assembliesToInclude.Add(typeof(Newtonsoft.Json.ConstructorHandling).GetTypeInfo().Assembly);
                assembliesToInclude.Add(typeof(Refit.AliasAsAttribute).GetTypeInfo().Assembly);
                assembliesToInclude.Add(typeof(System.Net.Http.ByteArrayContent).GetTypeInfo().Assembly);
                assembliesToInclude.Add(typeof(System.Net.NetworkInformation.IPAddressCollection).GetTypeInfo().Assembly);
                assembliesToInclude.Add(typeof(Plugin.Media.CrossMedia).GetTypeInfo().Assembly);
                assembliesToInclude.Add(typeof(Plugin.Media.Abstractions.CameraDevice).GetTypeInfo().Assembly);
                assembliesToInclude.Add(typeof(System.Linq.Enumerable).GetTypeInfo().Assembly);
    
                //Also do this for all your other 3rd party libraries
                Xamarin.Forms.Forms.Init(e, assembliesToInclude);
    

    So far I have not been able to successfully run my app when compiling with the .net native toolchain.

    Thursday, January 7, 2016 4:44 PM

All replies

  • User21407 posted

    Yeah, looks like you're doing it correctly. Here's what I have from my Xamarin.Forms app on UWP. This is in the App.xaml.cs file:

    // For .NET Native compilation, you have to tell Xamarin.Forms which assemblies it should scan for custom controls and renderers var otherAssemblies = new[] { typeof(MR.Gestures.ContentPage).GetTypeInfo().Assembly, typeof(MR.Gestures.UWP.Renderers.PageRenderer).GetTypeInfo().Assembly, typeof(NControl.UWP.NControlViewRenderer).GetTypeInfo().Assembly, typeof(ImageCircle.Forms.Plugin.UWP.ImageCircleRenderer).GetTypeInfo().Assembly }; // Use the special UWP overload of Forms.Init Xamarin.Forms.Forms.Init(e, otherAssemblies);

    Tuesday, December 6, 2016 2:47 PM
  • User89714 posted

    @pierce.boggan @JamesMontemagno - I've asked this question previously (although without specifying the .net native toolchain) at https://forums.xamarin.com/discussion/comment/230079

    Any chance somebody from Xamarin could provide a definitive answer?

    Tuesday, December 6, 2016 4:45 PM
  • User44776 posted

    For me I only had to include plugin assemblies like FormsPlugin.Iconize and didn't have to load other assemblies like System.Linq.Enumerable. Not sure if I had to? Haven't had any issue related to it yet. There seems to be no clear answers on this.

    Friday, March 2, 2018 1:23 AM