0

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.

Schotime
  • 15,707
  • 10
  • 46
  • 75
  • Does `type` represent a `Test` type or a ancestor of `Test`? – M.Babcock Jan 09 '12 at 02:00
  • Sorry yes..test represents a Test type – Schotime Jan 09 '12 at 02:15
  • Perhaps I'm missing something but `Type.GetCustomAttributes(bool)` doesn't appear to be a valid overload of `GetCustomAttributes` according to [the MSDN docs](http://msdn.microsoft.com/en-us/library/system.attribute.getcustomattributes.aspx). Is this something specific to StructureMap? – M.Babcock Jan 09 '12 at 03:22
  • its this one. http://msdn.microsoft.com/en-us/library/kff8s254.aspx – Schotime Jan 09 '12 at 03:42

1 Answers1

0

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 the DelimitedAttribute. You could try to add the AllowPartiallyTrustedCallers attribute to the plugin assembly.

Community
  • 1
  • 1
shamp00
  • 11,106
  • 4
  • 38
  • 81