Tony
Tony

Reputation: 39

Silverlight 4, MEF, Export/Import errors, Mefx doesn't want to work

Out of frustration and more than 3 days googling up this issue... i have no choice but to bother you guys with my question.

i am creating a Silverlight application. I am using MEF. When i try to run my application i get the following error.

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]

and its Inner exception is as follow...

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

Ok. my code is very simple since it's a test application.

i have an Interface IRetailModel

namespace IFG.Silverlight.Client.Common
{
    public interface IRetailModel
    { ............

then i have a class that implements this interface

namespace IFG.Silverlight.Client.Model
{
    [Export(typeof(IRetailModel))]
    public class RetailModel : IRetailModel
    { .................

Then I have my ViewModel for the View

namespace IFG.Silverlight.Client.ViewModel
{
    [PartCreationPolicy(CreationPolicy.NonShared)]
    [Export(ViewModelTypes.MenuViewModel)]
    public class MenuViewModel : IFGViewModelBase
    {
 IRetailModel _model;

        [ImportingConstructor]
        public MenuViewModel(IRetailModel model)
        {

Well, i found that there is a magical tool called MefX that it's supposed to debug deep to the bone your code and tells you what's going on... I havent been able to get this to work.

I followed directions from this article http://blogs.msdn.com/b/nblumhardt/archive/2009/09/24/debug-composition-from-within-visual-studio.aspx

When i try to run it says

Error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Then went back to Google and i found this Visual MefX (which is the same but with a GUI) and i can load the .xap but basically it gives me the same info that i get from Visual Studio. I can't find the darn [BECAUSE]...

I am really, HONESTLY AND DEEPLY, frustrated with this situation. Can anyone explain to me where am i failing to get MefX to do its job? I know the risk of dealing with these Overnight Frameworks (lack of documentation, buggy, etc etc) that MEF seems to be, but Prism is not a option to me (i feel like buying a M16 to kill a fly when i can use my finger).

Thank you

Upvotes: 1

Views: 1521

Answers (1)

Daniel Plaisted
Daniel Plaisted

Reputation: 16744

For future reference, an updated version of Visual Mefx is attached to this blog post: How to Debug and Diagnose MEF Failures. It is also part of MEFContrib, although I'm not sure if the MEFContrib version has all the changes from the version in the blog post.

Upvotes: 2

Related Questions