2010-12-14 98 views
1

出于挫折和超过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恩告诉你发生了什么事......我没有能够得到这个工作。

我跟着从这篇文章http://blogs.msdn.com/b/nblumhardt/archive/2009/09/24/debug-composition-from-within-visual-studio.aspx

方向当我尝试运行它说

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来杀死苍蝇手指)。

谢谢

+0

没关系的家伙...我忘了添加一个对我的ViewModel DLL的引用......就这么简单...... :( – Tony 2010-12-14 17:49:08

回答