2010-12-08 76 views
3

我有一個參考應用程序正在工作,現在已經破產,我不知道爲什麼。給我的問題的代碼基本上是Prism的ModularityWithMef Quickstart示例的精確副本。引導程序模塊是Quickstart的完全副本,除了添加模塊發現邏輯。所以我不包括這裏。我在Shell的View代碼中遇到的問題與QuickStart的Shell Codebehind幾乎完全相同。該代碼是 - 在此功能發生引導程序Prism w/Mef Bootstrapping問題

namespace MvvmRefVer 
{ 
    using System.ComponentModel; 
    using System.ComponentModel.Composition; 
    using System.Diagnostics; 
    using System.Globalization; 
    using System.Windows; 

    using Microsoft.Practices.Prism.Logging; 
    using Microsoft.Practices.Prism.Modularity; 

    [Export] 
    public partial class Shell : Window, IPartImportsSatisfiedNotification 
    { 
     [Import(AllowRecomposition = false)] 
     private CallbackLogger logger; 

     [Import(AllowRecomposition = false)] 
     private IModuleManager moduleManager; 

     public Shell() 
     { 
      this.InitializeComponent(); 
     } 

     public void OnImportsSatisfied() 
     { 
     } 
     private void WindowClosing(object sender, CancelEventArgs e) 
     { 
      Application.Current.Shutdown(); 
     } 

     private void WindowLoaded(object sender, RoutedEventArgs e) 
     { 
      this.moduleManager.LoadModule("NavigationViewControlModule"); 
     } 
    } 

問題 -

protected override DependencyObject CreateShell() 
    { 
     var d = this.Container.GetExportedValue<Shell>(); 
     return d; 
    } 

當GetExportedValue被調用並[Import(AllowRecomposition = false)]以上ModuleManager會的定義存在時,該函數調用將產生一個異常未定義。如果我註釋掉Import行,外殼將正確加載,但不初始化moduleManager。

我的問題是我沒有足夠的MEF經驗來了解問題所在。在查看mef目錄時,我可以看到Prism Modularity庫已經加載。

回答

0

發佈消息和未定義異常的堆棧跟蹤將有所幫助。

有關解決MEF問題的一般幫助,請參閱我的博客文章How to Debug and Diagnose MEF Failures

+0

感謝您的聯繫。隨着信息,我發現我的問題。我有一個按需加載的模塊,但是在數據初始化之前在啓動時加載。該模塊拋出了空參數異常。開始熱愛MEF,但必須學習新的思維方式來解決這些類型的問題。 – 2010-12-09 18:41:35