我正在使用结构图从子目录加载插件。
主应用程序和插件都引用 FileHelpers dll。 FileHelpers 具有放置在类上的属性,用于定义记录的分隔符。这些是在我的插件中定义的。例如。
[Delimited('\t')]
public class Test {
public string name;
}
FileHelpers 实用程序使用插件提供的类定义从主应用程序运行。如果我将插件 dll 放在主应用程序下面的目录中,那么我会遇到 FileHelpers 库的问题,抱怨找不到该属性,但是如果将其放置在主库旁边(同一文件夹),则它可以正常工作。
我在代码中添加了一些进一步的调试语句,并发现
var type = typeof(Test);
var attributes = type.GetCustomAttributes(true);
使用了 if 而不是特定的(FileHelpers 正在使用的)
var attributes = type.GetCustomAttributes(typeof(DelimitedAttribute), true);
,然后它可以毫无问题地找到自定义属性。
我认为这可能是 SM 的事情,但尝试过 MEF 并使用 Assembly.Load() 进行操作,并且发生了同样的事情。
I am using Structure Map to load plugins from a child directory.
Both the main app and the plugin reference the FileHelpers dll. FileHelpers has attributes that you put on a class to define what the record is delimited by. These are defined in my plugin. eg.
[Delimited('\t')]
public class Test {
public string name;
}
The FileHelpers utitlity is run from the main app using the class definitions provided by the plugins. If I put the plugin dll in a directory underneath the main application then I get an issue with the FileHelpers library complaining that the attribute cannot be found, however if it is placed next to the main library (same folder), then it works fine.
I have placed some further debug statements into my code and have found that if
var type = typeof(Test);
var attributes = type.GetCustomAttributes(true);
is used and not the specific (the one FileHelpers is using)
var attributes = type.GetCustomAttributes(typeof(DelimitedAttribute), true);
then it finds the custom attributes without any troubles.
I thought this may have been a SM thing but have tried MEF and by doing it using Assembly.Load() and the same thing happens.
发布评论
评论(1)
我认为您遇到了描述的问题
根据答案中链接的博客文章,看起来插件 dll 需要强命名且完全受信任,否则
GetCustomAttributes
将过滤掉DelimitedAttribute
。您可以尝试添加AllowPartiallyTrustedCallers
属性到插件程序集。I think you are running into the issue described here.
According to the blog post linked in the answer, it looks like the plugin dll would need to be strongly named and fully trusted, otherwise
GetCustomAttributes
will filter out theDelimitedAttribute
. You could try to add theAllowPartiallyTrustedCallers
attribute to the plugin assembly.