0

I'm doing a project in Prism WPF, and I want to use fody.costura to have only one executable and a folder of Prism modules, when i Add costura to the project and start the application prism does not find the modules in the directory: .\Modules I already tried all of the other methods of Initialization of modules, but the bootstrapper doesnt find them , it is important to say that all the dependencies of my modules are included in the initial bootstrap project.

Does anyone know how to solve the loading problem of modules in prism, when using fody.costura?

--------------------edit-------------------------

I am adding the code:

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

        protected override void InitializeShell()
        {
            Application.Current.MainWindow.Show();
        }


        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new DirectoryModuleCatalog() { ModulePath = @".\Modules" };
        }



        protected override void ConfigureModuleCatalog()
        {
            var moduleCatalog = (ModuleCatalog)ModuleCatalog;
        }

And the Error I got is: The lenght of the string cannot be zero.

StackTrace  "   en System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)\r\n   en System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)\r\n   en System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)\r\n   en System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)\r\n   en System.Reflection.Assembly.LoadFrom(String assemblyFile, Evidence securityEvidence)\r\n   en System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)\r\n   en System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName)\r\n   en System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName)\r\n   en Prism.Modularity.DirectoryModuleCatalog.InnerLoad()\r\n   en Prism.Modularity.ModuleCatalog.Initialize()\r\n   en Prism.Modularity.ModuleManager.Run()\r\n   en Prism.Unity.UnityBootstrapper.InitializeModules()\r\n   en Prism.Unity.UnityBootstrapper.Run(Boolean runWithDefaultConfiguration)\r\n   en Prism.Bootstrapper.Run()\r\n   en NFE2018.App.OnStartup(StartupEventArgs e) en C:\\Users\\arman\\documents\\visual studio 2017\\Projects\\NFE2018\\NFE2018\\App.xaml.cs:línea 33\r\n   en System.Windows.Application.<.ctor>b__1_0(Object unused)\r\n   en System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)\r\n   en System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)"  string

Exception appears here:

 protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);


            var bootstrapper = new Bootstrapper();
            bootstrapper.Run();    <-------- Here
        }
Armando Ramirez
  • 1,111
  • 1
  • 6
  • 5
  • 3
    Share the code which is being used to load modules. – Sham Oct 08 '18 at 06:12
  • @Sham I added the code, thanks – Armando Ramirez Oct 10 '18 at 12:14
  • When you say that you're using Fody.Costura, do you mean that you're trying to embed the modules with it? Could you please post the Fody.Costura code (e.g. the FodyWeavers.xml file)? – Eliza Bennet Oct 16 '18 at 16:41
  • Also, shouldn't the Module path be to @"\Modules" (without the dot)? – Eliza Bennet Oct 16 '18 at 16:42
  • Im triyng to embed all the dependencies but the modules, the idea is that the principal/ bootstrap app load all the dependencies keith costura, and the the app load the modules from the modules path, practically my fodyweavers is a default one without properties – Armando Ramirez Oct 16 '18 at 16:43

1 Answers1

1

It sounds like the problem might not be with Fody.Costura - make sure that the modules are all getting copied into the output directory (if you're using MS Visual Studio, then right-click the files and make sure that "Copy to Output Directory" has either "Always Copy" or "Copy if Newer" selected.

Let me know if that isn't the solution, you may need to embed the module dependencies with ILMerge instead (that is, embed them into the individual modules).

---- EDIT ----
After a little more thought about the way modules are supposed to work in Prism, I suspect the second solution is more likely.

Eliza Bennet
  • 179
  • 4
  • 17