0
votes

I register my module views in the Initialize method of module class in this way;

//CalendarModule.cs
public void Initialize() 
{ 
   _container.RegisterType<object, CalendarModuleView>(nameof(CalendarModuleView));               
}

And I load my modules by calling ModuleManager.LoadModule("CalendarModule");. After module initialized, I navigate to my newly loaded module;

_regionManager.RequestNavigate(RegionNames.MainContentRegion, "CalendarModuleView");

So far there is no problem. Everythig works just I expected. I can navigate through all on-demand modules.

But when I try to replace view registration with _container.RegisterTypeForNavigation<CalendarModuleView>(); I get following error during module loading;

An exception of type 'Prism.Modularity.ModuleInitializeException' occurred in Prism.Wpf.dll but was not handled in user code

Additional information: An exception occurred while initializing module 'CalendarModule'.

Inner Exception: {"Could not load file or assembly 'Prism.Unity.Wpf, Version=6.2.0.0, Culture=neutral, PublicKeyToken=91a96d2a154366d8' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"Prism.Unity.Wpf, Version=6.2.0.0, Culture=neutral, PublicKeyToken=91a96d2a154366d8"}

I wonder if RegisterTypeForNavigation<T> container extension method does the same work with RegisterType<object, T>(nameof(T)) container method. If yes, what causes preceeding error? Thanks!

FYI: My modules' initialization mode are OnDemand.

I use Prism.Unity as DI container.

1
Have you deployed the Prism.Unity.Wpf.dll. Does it exist in the folder where you start the application from?Jehof
I suspect you use different projects for CalendarModule and the main application? If so, try updating the prism nuget packages for each one.Domysee
@Domysee Yes you are right. My modules are separate projects inside a solution. I realized the main projects' packages were old. After nuget update, the problem was solved. Thank you!T.Y. Kucuk
@T.Y.Kucuk I've added it as answer, with a bit more detail to it.Domysee

1 Answers

1
votes

The error is caused because the packages of the main project are not the same version as the one referenced in the module.

Visual Studio copies only the assemblies referenced in the main project to the output directory.

Since the assembly of your module expects a prism assembly with a higher version number, it throws the exception you mentioned.

Updating all packages should resolve the issue.