When running the below code a type is never returned, despite there being a class with the correct attribute assigned. In fact the attr array always has a length of 0.
Assembly a = Assembly.LoadFile(file);
foreach (Type t in a.GetTypes())
{
object[] attr = t.GetCustomAttributes(typeof(SchemeNameAttribute), false);
foreach (object attribute in attr)
{
SchemeNameAttribute schemeName = attribute as SchemeNameAttribute;
if (schemeName != null && schemeName.Name.ToLower() == brickName.ToLower() )
{
return t;
}
}
}
if I change it to use:
object[] attr = t.GetCustomAttributes(false);
then it picks up one custom attribute of type SchemeNameAttribute for the Type, but
SchemeNameAttribute schemeName = attribute as SchemeNameAttribute;
always returns a null value for schemeName.
Any ideas?