Attributes Not Reading with Reflection?

  • Thread starter Thread starter localhost
  • Start date Start date
L

localhost

I have a classdecorated with a custom attribute.

I tried to load it and inspect the attributes with Reflection. Within
my code, I am never able to find the custom attribute. However, if I
fire up QuickWatch from within VS.NET 2003, I can see the attribute
clearly.

Namespaces are fully qualified and etc. Why would things not work?

Assembly tempAsy = Assembly.LoadFrom( @"test.dll" );
foreach ( System.Reflection.Module subModule in tempAsy.GetModules() )
{
foreach ( Type childType in subModule.GetTypes() )
{
object[] typeAttributes = childType.GetCustomAttributes(
typeof(testspace.TestThing), true );
}
}

typeAttributes always shows zero items, but setting a break point and
visually inspecting with the Watch shows the attribute clearly there.

Help?
 
Hello,

Thanks for your post. According to your code, it seems that you are trying
to get the custom attributes applied to testspace.TestThing. Since Watch
shows the attibute, please check if there is any applied to
testpace.TestThing.

I look forward to hearing from you.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top