启动Prism 7应用程序时App构造函数中的Null Exception

时间:2018-01-01 19:12:27

标签: xamarin.forms prism

我升级了一个xamarin表单应用程序以使用prism 7.当应用程序启动时(android项目),它在此行崩溃

System.ArgumentNullException: Value cannot be null.
Parameter name: path1

错误是

using Prism;
using Prism.Ioc;
using Prism.Mvvm;
using Prism.Ninject;
using SunBaseApp.Helpers;
using Xamarin.Forms;

[assembly: Xamarin.Forms.Xaml.XamlCompilation(Xamarin.Forms.Xaml.XamlCompilationOptions.Compile)]

namespace SunBaseApp
{
    public partial class App : PrismApplication
    {
        public App() : this(null) { }

        public App(IPlatformInitializer initializer = null) : base(initializer) { }

        protected override async void OnInitialized()
        {
            InitializeComponent();

            await NavigationService.NavigateAsync("/NavigationPage/LoginPage");
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            var cont = containerRegistry.GetKernel();

            cont.Bind<IAppSettings>().To<AppSettings>().InSingletonScope();
            cont.Bind<IDataService>().To<DataService>().InSingletonScope();

            containerRegistry.RegisterForNavigation<NavigationPage>();
            containerRegistry.RegisterForNavigation<LoginPage, LoginPageModel>();
            containerRegistry.RegisterForNavigation<MainPage, MainPageModel>();
            containerRegistry.RegisterForNavigation<SettingsEditPage, SettingsEditPageModel>();
            containerRegistry.RegisterForNavigation<StatPage, StatPageModel>();
            containerRegistry.RegisterForNavigation<WebsiteListPage, WebsiteListPageModel>();
            containerRegistry.RegisterForNavigation<WebsiteEditPage, WebsiteEditPageModel>();
        }
    }    
}

预发布版本以及myget的最新版本:7.0.0.343-ci。

我没有用prism 6.3得到这个错误。

App.xaml.cs:

<?xml version="1.0" encoding="utf-8" ?> <prism:PrismApplication xmlns="http://xamarin.com/schemas/2014/forms"
                        xmlns:prism="clr-namespace:Prism.Ninject;assembly=Prism.Ninject.Forms"
                        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                        x:Class="SunBaseApp.App">

  <Application.Resources>
    <ResourceDictionary>
      <Color x:Key="WindowBackgroundColor">#97D3F3</Color>
      <Color x:Key="ButtonBackgroundColor">Green</Color>
      <Color x:Key="ButtonTextgroundColor">White</Color>
      <Color x:Key="textColor">Black</Color>

      <Style TargetType="Button">
        <Setter Property="BackgroundColor" Value="{DynamicResource ButtonBackgroundColor}" />
        <Setter Property="TextColor" Value="{DynamicResource ButtonTextgroundColor}" />
      </Style>

      <!--<Style TargetType="NavigationPage">
        <Setter Property="BarBackgroundColor" Value="Red"/>
        <Setter Property="BarTextColor" Value="Green"/>
      </Style>-->

      <!--<Style TargetType="NavigationPage">
        <Setter Property="BarBackgroundColor" Value="{DynamicResource ButtonBackgroundColor}" />
      </Style>-->

    </ResourceDictionary>   </Application.Resources>

</prism:PrismApplication>

的App.xaml:

using Android.App;
using Android.Content.PM;
using Android.OS;
using Acr.UserDialogs;
using Prism;
using Prism.Ioc;

namespace SunBaseApp.Droid
{
    [Activity(Label = "SunBaseApp", Icon = "@drawable/icon2", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            ToolbarResource = Resource.Layout.toolbar;
            TabLayoutResource = Resource.Layout.tabs;

            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);

            LoadApplication(new App(new AndroidInitializer()));

            UserDialogs.Init(this);
        }

        public class AndroidInitializer : IPlatformInitializer
        {
            public void RegisterTypes(IContainerRegistry containerRegistry)
            {
            }
        }
    }
}

Mainactivity:

{{1}}

非常感谢任何想法。

1 个答案:

答案 0 :(得分:3)

Ninject似乎在Droid上运行了一些问题。我建议您更新项目以使用另一个更稳定的容器。另请注意,除非您需要更高级的注册,否则使用最新版本不需要直接引用容器。像你所拥有的基本内容可以简单地注册如下:

containerRegistry.RegisterSingleton<IAppSettings, AppSettings>();