Xamarin Forms fails to create an instance of DI container RRS feed

  • Question

  • User55216 posted

    I'm using Visual Studio 2017.

    Created the default Xamarin Forms project (.net standard 2.0 + android). No changes in project configuration, Debug mode.

    Compile -> Build -> Success (simple page with a standard text). Works in simulator, Xamarin Live.

    Added Unity/Autofac and created an instance of the container in App. The solution works in simulator, but fails on phone (Xamarin Live, or direct execution). This error can be reproduced in both Release/Debug modes.

    With Unity:

    ``` public App () { InitializeComponent();

        var c = new UnityContainer(); //this is the only line for Unity example
        MainPage = new App2.MainPage();


    Object reference not set to an instance of an object

    p.s. tried the approach to skip linking assembly System.Core

    With Autofac Fails on RegisterType with exception:

    Target of Add is null (NullReferenceException)

    Saturday, March 17, 2018 3:44 AM

All replies

  • User366412 posted

    I have just had the same issue. After this error my Visual Studio hangs and I have to restart it. I use Autofac and Xamarin Live Player on my device Xiaomi Mi A1 with Android Oreo 8.0.

    From NetStandard 2.0 library I reference * Prism.Unity.Forms v7.0.0.396, * Xamarin.Forms v2.5.0.280555 * NETStandard.Library v2.0.1 * Autofac v4.6.2

    From the Android project I reference * Xamarin.Android.Support.Design, * Xamarin.Android.Support.v7.AppCompat, * Xamarin.Android.Support.v4, * Xamarin.Android.Support.v7.CardView, * Xamarin.Android.Support.v7.MediaRouter - everything on version * Xamarin.Forms v2.5.0.280555

    Sunday, March 18, 2018 8:35 PM