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.
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
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!
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With