出於挫折和超過3天googling這個問題...我別無選擇,只是打擾你們與我的問題。Silverlight 4,MEF,導出/導入錯誤,Mefx不想工作
我正在創建一個Silverlight應用程序。我正在使用MEF。當我嘗試運行我的應用程序時,出現以下錯誤。
The invocation of the constructor on type 'IFG.Silverlight.Client.Views.MenuView' that matches the specified binding constraints threw an exception. [Line: 25 Position: 47]
其內部異常是跟隨...
The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) No valid exports were found that match the constraint '((exportDefinition.ContractName == "MenuViewModel") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "IFG.Silverlight.Client.ViewModel.MenuViewModel".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))', invalid exports may have been rejected.
Resulting in: Cannot set import 'IFG.Silverlight.Client.Views.MenuView.ViewModel (ContractName="MenuViewModel")' on part 'IFG.Silverlight.Client.Views.MenuView'. Element: IFG.Silverlight.Client.Views.MenuView.ViewModel (ContractName="MenuViewModel") --> IFG.Silverlight.Client.Views.MenuView
確定。我的代碼非常簡單,因爲它是一個測試應用程序。
我有一個接口IRetailModel
namespace IFG.Silverlight.Client.Common
{
public interface IRetailModel
{ ............
那麼我實現了這個接口
namespace IFG.Silverlight.Client.Model
{
[Export(typeof(IRetailModel))]
public class RetailModel : IRetailModel
{ .................
然後,我有我的視圖模型爲View
namespace IFG.Silverlight.Client.ViewModel
{
[PartCreationPolicy(CreationPolicy.NonShared)]
[Export(ViewModelTypes.MenuViewModel)]
public class MenuViewModel : IFGViewModelBase
{
IRetailModel _model;
[ImportingConstructor]
public MenuViewModel(IRetailModel model)
{
好一個班,我發現有一個名爲MefX的神奇工具,它應該深入調試你的代碼a恩告訴你發生了什麼事......我沒有能夠得到這個工作。
方向當我嘗試運行它說
Error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
然後回到谷歌,我發現這種視覺MEFX(這是相同的,但有一個GUI)我可以加載.xap,但基本上它給了我從Visual Studio獲得的相同信息。我無法找到該darn [因爲] ...
我真的,誠實和深刻,沮喪與這種情況。任何人都可以向我解釋我無法讓MefX做什麼工作嗎?我知道處理這些隔夜框架(MEF似乎沒有文檔,馬車等)的風險,但棱鏡不是我的選擇(當我可以使用我的時候,我想買一個M16來殺死蒼蠅手指)。
謝謝
沒關係的傢伙...我忘了添加一個對我的ViewModel DLL的引用......就這麼簡單...... :( – Tony 2010-12-14 17:49:08