zoukankan      html  css  js  c++  java
  • Prism 5 + MEF中的ModuleCatalog.CreateFromXaml问题

      protected override IModuleCatalog CreateModuleCatalog()
            {
                return Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(new Uri("ModuleCatalog.xaml", UriKind.Relative));
            }

    .net的背景,就不说了。用这个代码作为开头吧。在Bootstrapper载入部件时需要用到。

    ModuleCatalog有很多种方法可以导入,总得来说就是灵活的。但偏偏这种看上去比较酷一点的(没有MyApp.exe.config文件,也不写死在cs代码里),却怎么也调试不出来。报的错误有这几种:

    There is currently no moduleTypeLoader in the ModuleManager that can retrieve the specified module
    
    {"“f”(十六进制值 0x0C)是无效的字符  
    
    The IModuleCatalog is required and cannot be null in order to initialize the modules.  

    问题主要出在:

    1. Xaml文件中定义的ModuleName与ExportModule的名称不符

    2. Xaml文件的编译方式选择不正确

    3. 忘了

    我项目中通过的几个相关代码和设置如下,环境vs2013,Prism 5 + MEF,wpf。

    MuduleCatalog.xaml:

    <Modularity:ModuleCatalog xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                              xmlns:Modularity="clr-namespace:Microsoft.Practices.Prism.Modularity;assembly=Microsoft.Practices.Prism.Composition">
        <Modularity:ModuleInfo Ref="file://XianFeng.Client.Modules.Notify.dll"
                               ModuleName="NotifyModule"
                               InitializationMode="WhenAvailable"
                               ModuleType="XianFeng.Client.Modules.Notify.NotifyModule, XianFeng.Client.Modules.Notify" />
    </Modularity:ModuleCatalog>

    相应的,xxxNotify.dll中的输出文件NotifyModule.cs:

    namespace XianFeng.Client.Modules.Notify
    {
        [ModuleExport("NotifyModule", typeof(NotifyModule))]
        public class NotifyModule : IModule
        {
            [Import]
            public IRegionManager regionManager;
    
            public void Initialize()
            {
                this.regionManager.RegisterViewWithRegion(RegionNames.NotifyRegion, typeof(Views.Notify));
            }
        }
    }

    ModuleCatalog.xaml文件的属性:

    生成操作是Resource是我自己摸出来的,bing到的一些资料上说的都是老版本的吧,都不对,包括那个Mike Taulty的视频的也不对。

    解决问题!

  • 相关阅读:
    Servlet的几种跳转(转)
    Java String.split()用法小结(转)
    表单数据提交的方法
    gedit文本编辑器乱码解决办法
    J-Link烧写bootloader到mini2440的Nor Flash
    虚拟机安装Fedora10系统遇到异常
    linux系统忘记root密码怎么办?
    编译busybox时出错及解决方案
    source insight代码查看器如何自定义添加文件类型
    < Objective-C >文件操作-NSFileHandle
  • 原文地址:https://www.cnblogs.com/tianciliangen/p/4955753.html
Copyright © 2011-2022 走看看