2010-12-17 69 views
0

我开发了一个应用程序,它使用MEF将所有可用的UserControls显示在窗体上。用户控件和表单都驻留在同一个程序集中。这一切工作正常,当我从XP启动exe,但在使用Windows 7机器时抛出异常。有没有解决这个问题的建议。Windows 7上的MEF异常

+4

我们需要一些代码或示例,以及明确的错误信息。 – IAbstract 2010-12-17 01:36:35

回答

0

嗨,

我把这个整理出来。我在应用程序中使用Log4Net,出于一些奇怪的原因,Winforms的安装应用程序没有使用log4not xml文件。这在安装的版本中缺少,这就是应用程序出现错误的原因。

感谢您的回复。

1

我的第一个建议是展示你的构图方法和一些代码示例。否则,我会消除除了一个UserControl之外的所有负载。从那里开始。请确保您:

[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. 
    */ 
    ... 
} 

...然后在主机应用:

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

我使用的IEnumerable做为一个例子,因为你期望的负载几个用户控件。我假设你将加载控件以便一次显示。否则,如果你不想让他们一下子,而是需求,我仍然会列举这样:

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

这样你可以遍历,对空测试UserControls[index].Value

没有更多的信息,这真的是我能为你做的最好的。