Ninject StandardKernel System.ArgumentNullException:值不能为null。参数名称:path1

lea*_*ner 4 ninject xamarin

我正在学习Xamarin,我想Ninject用于IoC容器和依赖注入。我在社区上添加了Ninject 3.3.4使用NuGetVisual studio 2017。我在App.Xaml.cs的以下代码行中收到错误:

Kernel = new StandardKernel(new TripLogCoreModule(), new TripLogNavModule(mainPage.Navigation));
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Ninject StandardKernel System.ArgumentNullException:值不能为null。参数名称:path1

我花了大约2个小时上网,却找不到解决我问题的方法。

最后,我发现了自己的疏忽,所以我想发布此问题并回答我自己的问题,以防其他人(像我这样的新手)犯此错误。

Emm*_*RIN 6

就我个人而言,NinjectNinject.PCL软件包都出错

尝试使用NinjectSettings构建StandardKernel

var settings = new Ninject.NinjectSettings() { LoadExtensions = false };
Kernel = new StandardKernel(settings, new ViewModelsModule());
Run Code Online (Sandbox Code Playgroud)

问候


lea*_*ner 5

我的疏忽是我安装了错误的软件包。我应该安装Portable.Ninject.

为了解决这个问题,我Ninject3.3.4从我所有的项目中卸载了,然后Portable.Ninject 3.3.1通过 NuGet 包安装(在撰写本文时最新的稳定版本)。

我希望这可以帮助那些可能犯类似错误的人并节省时间!