将fody.costura添加到项目后,在棱镜WPF C#中加载问题模块

时间:2018-10-08 05:39:59

标签: c# .net wpf prism fody-costura

我正在Prism WPF中做一个项目,我想使用fody.costura仅包含一个可执行文件和一个Prism模块文件夹,当我向项目中添加costura并启动应用程序棱镜时找不到该模块在目录:。\ Modules中,我已经尝试了模块初始化的所有其他方法,但是bootstrapper找不到它们,重要的是要说我模块的所有依赖项都包含在初始的bootstrap项目中。

在使用fody.costura时,有人知道如何解决棱镜模块的加载问题吗?

--------------------编辑------------------------- < / p>

我要添加代码:

 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;
        }

我得到的错误是: 字符串的长度不能为零。

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

异常出现在这里:

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


            var bootstrapper = new Bootstrapper();
            bootstrapper.Run();    <-------- Here
        }

1 个答案:

答案 0 :(得分:1)

听起来好像Fody.Costura可能没有问题-确保将所有模块都复制到输出目录中(如果您使用的是MS Visual Studio,请右键单击文件并制作确保“复制到输出目录”已选择“始终复制”或“如果更新则复制”。

让我知道这是否是解决方案,您可能需要使用ILMerge嵌入模块依赖项(即,将它们嵌入到各个模块中)。

----编辑----
在对模块应该在Prism中工作的方式进行了更多思考之后,我怀疑第二种解决方案更有可能。