Windows 7 上的 MEF 异常

发布于 2024-10-08 05:02:46 字数 122 浏览 0 评论 0原文

我开发了一个应用程序,它使用 MEF 来获取可在表单上显示的所有用户控件。用户控件和窗体都驻留在同一个程序集中。当我从 XP 启动 exe 时,一切正常,但在使用 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小女人ら 2024-10-15 05:02:46

我的第一个建议是展示你的组合方法和一些代码示例。否则,我将消除除一个 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.
     */
    ... 
}

...然后在 Host 应用程序中:

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

我在这里使用 IEnumerable 作为示例,因为您希望加载多个 UserControl。我假设您将立即加载要显示的控件。否则,如果您不想一次性全部使用它们,而是按需,我仍然会这样枚举:

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

这样您就可以迭代、测试 UserControls[index].Value为空。

如果没有更多信息,这确实是我能为您做的最好的事情。

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.

别挽留 2024-10-15 05:02:46

嗨,

我已经解决了这个问题。我在应用程序中使用 Log4Net,由于一些奇怪的原因,Winforms 的安装应用程序没有采用 log4not xml 文件。安装的版本中缺少此功能,这就是应用程序出错的原因。

感谢您的回复。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文