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

3

5

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.

Daemon answered 29/5, 2018 at 11:28 Comment(0)
D
5

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!

Daemon answered 29/5, 2018 at 11:34 Comment(1)
yes but this is not compatible with .net standard class librariesStylist
E
8

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

Erving answered 16/8, 2018 at 18:42 Comment(0)
D
5

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!

Daemon answered 29/5, 2018 at 11:34 Comment(1)
yes but this is not compatible with .net standard class librariesStylist
D
1

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());

Doolie answered 5/9, 2019 at 19:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.