Chinjoo
Chinjoo

Reputation: 2792

MEF Exception on Windows 7

I have developed an application that uses MEF to get all the UserControls available to be shown on a form. The user controls and the form both reside in the same assembly. This all works fine when I launch the exe from XP, but throw exception when using Windows 7 machine. Is there any suggestion to solve this issue.

Upvotes: 0

Views: 188

Answers (2)

Chinjoo
Chinjoo

Reputation: 2792

HI,

I got this sorted out. I was using Log4Net in the application and for some strange reasons, the setup application for the Winforms was not taking the log4not xml file. This was missing in the installed version and this was the reason of the application being getting errored out.

Thanks for your replies.

Upvotes: 0

IAbstract
IAbstract

Reputation: 19881

My first suggestion is to show your method of composition and some code examples. Otherwise, I would eliminate all the loads except one UserControl. Start from there. Make sure that you:

[Export(typeof(IUserControl))]
public class myUserControl : UserControl, IUserControl
{ 
    ... 
    /*
     * control to be exported:
     * note: you can forego IUserControl and just use UserControl
     *       but make sure you do so throughout the import and
     *       export attributes.
     */
    ... 
}

...and then in the Host app:

[ImportMany(typeof(IUserControl))]
IEnumerable<IUserControl> UserControls {get;}

I am using IEnumerable here as an example because you are expecting load several UserControls. I am assuming that you will be loading the controls to be displayed at once. Otherwise, if you don't want them all at once, but rather on demand, I would still enumerate as such:

[ImportMany(typeof(IUserControl))]
IEnumerable<Lazy<IUserControl>> UserControls {get;}

This way you can iterate, test UserControls[index].Value for null.

Without more information, this is really the best I can do for you.

Upvotes: 1

Related Questions