简体   繁体   English

导入但未加载dll

[英]import but dll was not loaded

I have a class exported and in a different part of the code it is imported. 我有一个导出的类,并且在导入的代码的不同部分中。

[Import]
public IEnumerable<IRTAOperatorErrorNotifications> RTAOperatorErrorNotifications
{
    get { return m_RTAOperatorErrorNotifications; }
}

Now the DLL were the class resides is loaded into the application conditionally and in most cases it won't exist, so I'm wondering will this cause the program to crash if the DLL doesn't exist? 现在将类驻留的DLL有条件地加载到应用程序中,并且在大多数情况下它不存在,所以我想知道如果DLL不存在,这会导致程序崩溃吗? What I want is for the object to simply be set to null if the DLL isn't there so I can check and do the right thing. 我想要的是将该对象简单地设置为null(如果DLL不存在),以便我可以检查并做正确的事情。 Is there a way to conditionally import so the value is set to null if the class isn't loaded? 有没有一种方法可以有条件地导入,因此如果未加载该类,则将该值设置为null?

Thanks, 谢谢,

Suggested changes: since it is an IEnumerable you need to use ImportMany . 建议的更改:由于它是IEnumerable您需要使用ImportMany AllowDefault = true allows code to set it NULL when no import was found. AllowDefault = true允许代码在未找到导入时将其设置为NULL

[ImportMany(AllowDefault = true)]
public IEnumerable<IRTAOperatorErrorNotifications> RTAOperatorErrorNotifications { get; private set; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM