[英]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. 我已经开发了一个使用MEF的应用程序,该应用程序可将所有UserControls显示在表单上。 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. 当我从XP启动exe时,一切正常,但使用Windows 7机器时抛出异常。 Is there any suggestion to solve this issue. 有什么建议可以解决这个问题。
My first suggestion is to show your method of composition and some code examples. 我的第一个建议是展示您的编写方法和一些代码示例。 Otherwise, I would eliminate all the loads except one UserControl
. 否则,我将消除除一个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. 我在这里以IEnumerable为例,因为您希望加载多个UserControl。 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. 这样,您可以迭代并测试UserControls[index].Value
是否为null。
Without more information, this is really the best I can do for you. 没有更多信息,这确实是我能为您做的最好的事情。
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. 我在应用程序中使用Log4Net,由于某些奇怪的原因,Winforms的安装应用程序未使用log4not xml文件。 This was missing in the installed version and this was the reason of the application being getting errored out. 在安装的版本中缺少此功能,这是导致应用程序出错的原因。
Thanks for your replies. 多谢您的回覆。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.