简体   繁体   English

Windows 7上的MEF异常

[英]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.

相关问题 MEF抛出异常ImportCardinalityMismatchException? - MEF throws exception ImportCardinalityMismatchException? 在服务器上托管时出现MEF异常 - MEF exception when hosting on a server MEF,具有高级元数据和序列化异常的延迟加载 - MEF, Lazy loading with advanced metadata and serialization exception 使用MEF忽略构造函数异常,而Visual Studio不会在异常处中断 - Ignore constructor exceptions with MEF without Visual Studio breaking at the exception 我该如何处理与MEF相关的ReflectionTypeLoadException异常? - How can I deal with this MEF related ReflectionTypeLoadException exception? 使用MEF时从另一个程序集导入会引发异常 - Import from another assembly throws exception when using MEF 发现多个导出与MEF ImportMany的约束异常匹配 - More than one export was found that matches the constraint exception with MEF ImportMany MEF组合错误不传播内部异常(通过消息除外) - MEF Composition error not propagating inner exception (except through message) PRISM / MEF:2个窗口的视图模型如何相互通信? - PRISM/MEF: How can 2 windows' viewmodels talk to each other? 面向.NET4.5,SL和Windows Store应用的MEF for Portable Library Class - MEF for Portable Library Class targeting .NET4.5, SL and Windows Store apps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM