使用Visual Studio 2017 .

创建了默认的Xamarin Forms项目(.net standard 2.0 android) . 项目配置,调试模式没有变化 .

Compile -> Build -> Success (带标准文本的简单页面) .

添加 Unity/Autofac 并在 App 中创建了容器的实例 .

在Unity中:

Object reference not set to an instance of an object

类似于AutoFac

附:尝试过跳过链接程序集的方法 System.Core

upd.1

这是绝对标准的解决方案,只有一行代码:

public App ()
    {
        InitializeComponent();

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

Autofac的情况类似 . 但它在 RegisterType 失败,异常 Target of Add is null (NullReferenceException)

upd.2

  • 在Release和Debug模式下都失败了

  • 这在模拟器中没有失败!

  • 直接在手机上执行任何类型的操作失败(包括Xamarin Live)