When initializing the module with the error: "Value cannot be null"?

Good day!

Trying to learn how to do app with the use of Panther MVVM and IoC containers.

In the application used these libraries:
  • Prism.Wpf;
  • Prism.Autofac;
  • Autofac;

Optional: Prism.Mef(as it is almost not used).

Here is the suspect:
namespace DailyLog.Desktop.MainWindowMenu
{
 [ModuleExport(typeof(MainWindowMenuModule))] // Edinstvennoe where used "Prism.Mef"
 public class MainWindowMenuModule : IModule
{
[Import]
 public IRegionManager Region { get; set; }

 public void OnInitialized(IContainerProvider containerProvider)
{
 Region.RegisterViewWithRegion("MainWindowMenuRegion", typeof(HomeView));
}

 public void RegisterTypes(IContainerRegistry containerRegistry)
{

}
}
}


Here check module "MainWindowMenuModule" and the module.
namespace DailyLog.Desktop.MainWindowMenu
{
 public class MainWindowMenuModuleRegistry : Module
{
 protected override void Load(ContainerBuilder builder)
{
base.Load(builder);

builder.RegisterType<MainWindowMenuModule>();
builder.RegisterType<HomeView>();
}
}
}


Here is the loader:
namespace DailyLog.Desktop.MainWindowMenu
{
 public class Bootstrapper : AutofacBootstrapper
{
 protected override void ConfigureContainerBuilder(ContainerBuilder builder)
{
base.ConfigureContainerBuilder(builder);
builder.RegisterType<Shell.Views.Shell>();

 // Autofac registration module here...
builder.RegisterModule<MainWindowMenuModuleRegistry>();
}

 protected override void ConfigureModuleCatalog()
{
base.ConfigureModuleCatalog();

 // Register Prism module here...
 TypeNewsModule Type = typeof(MainWindowMenuModule);
 ModuleCatalog.AddModule(new ModuleInfo(typeNewsModule.Name typeNewsModule.AssemblyQualifiedName));
}

 protected override DependencyObject CreateShell()
{
 return Container.Resolve<Shell.Views.Shell>();
}

 protected override void InitializeShell()
{
base.InitializeShell();

 Application.Current.MainWindow = (Shell.Views.Shell)this.Shell;
Application.Current.MainWindow.Show();
}
}
}


The full text of the error:
Prism.Modularity.ModuleInitializeException: "An exception occurred while initializing module 'MainWindowMenuModule'.
- The exception message was: Value cannot be null.
Parameter name: context
Check the InnerException property of the exception for more information. If the exception occurred
while creating an object in a DI container, you can exception.GetRootException() to help locate the
root cause of the problem."


Logs:
Initially this exception was created in this call stack:
Autofac.ResolutionExtensions.ResolveService(Autofac.IComponentContext, Autofac.Core.Service, System.Collections.Generic.IEnumerable)
Prism.Autofac.Ioc.AutofacContainerExtension.Resolve(System.Type)
Prism.Modularity.ModuleInitializer.CreateModule(string)
Prism.Modularity.ModuleInitializer.CreateModule(Prism.Modularity.IModuleInfo)
Prism.Modularity.ModuleInitializer.Initialize(Prism.Modularity.IModuleInfo)


What is the actual problem?

P. s the link to GitHub in case... https://github.com/xXJamXx/DailyLog/tree/development
April 4th 20 at 13:13
1 answer
April 4th 20 at 13:15
Most likely, you have at the time of the call Region had a value of null. Try to run in debug mode, after putting a breakpoint at the beginning of the OnInitialized method. If there really is null, then check that the IRegionManager is registered in your IoC container, and the MainWindowModule will resolvida through the container
We tried to remove the call of the region, the identity of the error. - Elta.Corkery commented on April 4th 20 at 13:18
@Elta.Corkery, then it is easier to gather in debug with a normal stacktrace to a specific line showed - verda.Co commented on April 4th 20 at 13:21

Find more questions by tags C#