我正在尝试从Xamarin.Android应用程序的MainActivity初始化Ninject,但它在StandardKernel上抛出以下异常:
System.ArgumentNullException:值不能为null。 参数名称:path1
我有两个项目,1> SharedLibrary(.Net Standard 2.0)和Xamarin.Android Project
SharedLibrary中的代码:
public class Dependencies : NinjectModule
{
public override void Load()
{
Bind<IItemRepository>().To<TodoItemRepositoryADO>().InSingletonScope();
}
}
public class NinjectContainer
{
public static StandardKernel Container;
public static void Load()
{
var kernel = new StandardKernel(new Dependencies());
Container = kernel;
}
}
public class AppInitializer
{
public void Intialize()
{
NinjectContainer.Load();
}
}
MainActivity中的代码:
AppInitializer appInitializer = new AppInitializer();
appInitializer.Intialize();
堆栈跟踪:
0xFFFFFFFFFFFFFFFF in System.Diagnostics.Debugger.Mono_UnhandledException_internal C#0x1 in System.Diagnostics.Debugger.Mono_UnhandledException C#0x26 in object.e813dbd6-dc94-4712-a75f-815827c29a49 C#0xD in Ninject.Modules.ModuleLoader中的System.IO.Path.Combine C#0x7。 C#0x4D 在 System.Linq.Enumerable.SelectArrayIterator.MoveNext C# 0x54英寸 System.Linq.Enumerable.WhereEnumerableIterator.MoveNext C# 0x3E in System.Linq.Enumerable.SelectManySingleSelectorIterator.MoveNext C# 0x75英寸 System.Linq.Enumerable.SelectManySingleSelectorIterator.MoveNext C# System.Linq.Lookup中的0x2C.Create C#0x12 in System.Linq.GroupedEnumerable.GetEnumerator C#0x5A in Ninject.Modules.ModuleLoader.LoadModules C#0xC in Ninject.KernelBase.Load C#0xBC in Ninject.KernelBase..ctor C#0xC in Ninject.KernelBase..ctor C#0x2 in Ninject.StandardKernel..ctor C#0xF 在SharedCode.NinjectContainer.Load中 C:\ Users \ dishah \ source \ repos \ ToDo \ SharedCode \ NinjectContainer.cs:11,13 C# 在SharedCode.AppInitializer.I根中的0x1 C:\ Users \ dishah \ source \ repos \ ToDo \ SharedCode \ AppInitializer.cs:11,13 C# ToDo.MainActivity.OnCreate中的0x8C C:\ Users \ dishah \ source \ repos \ ToDo \ ToDo \ MainActivity.cs:53,13 C#0x11 在Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ C#0x17中 object.e813dbd6-dc94-4712-a75f-815827c29a49 C#
答案 0 :(得分:0)
尝试使用 NinjectSettings 构建 StandardKernel :
var settings = new Ninject.NinjectSettings() { LoadExtensions = false };
Kernel = new StandardKernel(settings, new ViewModelsModule());
致谢