How to enter a URI to configure ModuleCatalog in Prism WPF

I'm a little upset by the prism. Something that should be so simple really makes me stuck!

I am trying to load my ModuleCatalog from a file. I created the ModuleCatalog.xaml file in my shell project. In the properties of the file, I deleted the Custom Tool action and I installed Build Action to Resource (I also tried Content).

Here is the code I have:

public class Bootstrapper : UnityBootstrapper
{
   protected override IModuleCatalog GetModuleCatalog()
   {
      var uri = new Uri("/ShellProject;component/ModuleCatalog.xaml", UriKind.Relative);
      var catalog = ModuleCatalog.CreateFromXaml(uri);
      return catalog;

      // I have also tried this:
      //return (ModuleCatalog.CreateFromXaml(
      //        new Uri("ModuleCatalog.xaml", UriKind.Relative)));
   }
   ...

When I start, I get the following error:

IModuleCatalog is required and cannot be empty to initialize modules.

I'm at a dead end. The blogs I read and the videos I watched seem to indicate that I am doing it right.

I can’t think that I am the only one who ever downloaded my configuration from the xaml file in wpf, but I just can’t find it.

Any help would be great!

NOTES:


, , , :

protected override IModuleCatalog GetModuleCatalog()
{
  FileStream catalogStream = new FileStream(@".\ModuleCatalog.xaml",FileMode.Open);
  var catalog = ModuleCatalog.CreateFromXaml(catalogStream);
  catalogStream.Dispose();
  return catalog;
}
+3
4

, , Prism .pdb , .

, , Quickstarts, QS.

Prism, , , , , .

+1

, MEF WPF. - , . , , , , . , . boostrapper MEF Unity, WPF:

protected override IModuleCatalog CreateModuleCatalog()
{
    // MEF and Unity **BOTH** use the ModuleCatalog when configuring from a file
    return Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(
        System.IO.File.OpenRead("catalog.xaml"));
}

, "WpfModule1.dll", "WpfModule" 1 "WpfModule", "IModule", "catalog.xaml":

<Modularity:ModuleCatalog  
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
  xmlns:sys="clr-namespace:System;assembly=mscorlib"  
  xmlns:Modularity="clr-namespace:Microsoft.Practices.Prism.Modularity;assembly=Microsoft.Practices.Prism">
    <Modularity:ModuleInfo Ref="file:///WpfModule1.dll" 
        ModuleName="WpfModule"
        ModuleType="WpfModule1.WpfModule, WpfModule1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
        InitializationMode="WhenAvailable" />
</Modularity:ModuleCatalog>

, " ": "" " ": ", ". , .

+2

, ModuleCatalog.CreateFromXaml()

  • ModuleCatalog.xaml
  • ( 1.0.0.0, ). .: ModuleType = "MyProj.ModuleB.ModuleBModule, MyProj.ModuleB, Version = 1.0.0.0"
+1

:

IModuleCatalog , .

after upgrading from Prism 4.x to 5.0. This turned out to be due to the reorganization of the assembly - the Microsoft.Practices.Prism assembly specified in ModuleCatalog.xaml no longer exists ; now Microsoft.Practices.Prism.Composition . It's easy to overlook the squidgly line in the IDE.

So, for Prism 5.0, the root element in ModuleCatalog.xaml should look like this:

<Modularity:ModuleCatalog  
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
  xmlns:sys="clr-namespace:System;assembly=mscorlib"  
  xmlns:Modularity="clr-namespace:Microsoft.Practices.Prism.Modularity;assembly=Microsoft.Practices.Prism.Composition">
+1
source

Source: https://habr.com/ru/post/1771136/


All Articles