GetCustomAttribute始终返回null

时间:2016-03-10 14:08:37

标签: reflection

我有一个属性类

 [AttributeUsage(AttributeTargets.Class)]
public class WizardAttribute : Attribute
{
    public bool AddGuid { get; set; }

    public WizardAttribute()
    {
    }

}

我试图通过像这样的反射获得这个属性

                    Assembly assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "bin\\some.dll");
                Type[] types = assembly.GetTypes();
                foreach (Type tt in types)
                {
                    if (tt.Name == "Somecontroller")
                    {
                        WizardAttribute attribute = (WizardAttribute)(tt.GetCustomAttribute(typeof(WizardAttribute)));
                    }
                }

并且属性始终为null

请帮忙

1 个答案:

答案 0 :(得分:0)

好的我发现它将加载程序集更改为

                    Assembly assembly = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "bin\\SwiftNess.Portal.dll");