Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ninject StandardKernel System.ArgumentNullException: value cannot be null. Parameter name: path1

I am a learning Xamarin and I wanted to use Ninject for IoC containers and dependency injection. I added Ninject 3.3.4 using NuGet package on Visual studio 2017 community. I receive error on the following line of code in my App.Xaml.cs:

Kernel = new StandardKernel(new TripLogCoreModule(), new TripLogNavModule(mainPage.Navigation));

I receive following error:

Ninject StandardKernel System.ArgumentNullException: value cannot be null. Parameter name: path1

I spent about 2 hours on the internet and couldn't find a solution to my problem.

Finally, I found the oversight that I made, so I thought to post this question and answer my own question, in case someone else (newbie like me) make this mistake.

like image 278
learner Avatar asked May 29 '18 11:05

learner


3 Answers

Personally, I had the error with both Ninject and Ninject.PCL packages

Try to build the StandardKernel with NinjectSettings :

var settings = new Ninject.NinjectSettings() { LoadExtensions = false };
Kernel = new StandardKernel(settings, new ViewModelsModule());

Regards

like image 113
Emmanuel DURIN Avatar answered Oct 09 '22 09:10

Emmanuel DURIN


The oversight that I made was that I installed the wrong package. I should have installed Portable.Ninject.

In order to fix this, I uninstalled the Ninject3.3.4 from all my projects and then installed Portable.Ninject 3.3.1 (latest stable version at the time of writing) via NuGet package.

I hope this helps and saves time for those people who may make similar mistake!

like image 35
learner Avatar answered Oct 09 '22 10:10

learner


Emmanuel DURIN had the right answer for using Ninject 3.3.4 with Xamarin.Forms .Net Standard.

var settings = new Ninject.NinjectSettings() { LoadExtensions = false }; Kernel = new StandardKernel(settings, new ViewModelsModule());

instead of

Kernel = new StandardKernel(new ViewModelsModule());

like image 1
rts Avatar answered Oct 09 '22 09:10

rts