Edited to rephrase question:
The following code is driving me nuts! I am trying to read the IDEiconAttribute from each class (e.g. ConsoleInput ) in a library. But, I cannot access the attribute (object) I retrieve as my IDEiconAttribute , so I can't call the IDEiconAttribute.Icon property. It refuses to be cast to IDEiconAttribute, even though when I print out the type, the type is IDEClassLibraryNS.IDEiconAttribute. In fact, I get the bizzare message "cannot cast IDEClassLibraryNS.IDEiconAttribute to IDEClassLibraryNS.IDEiconAttribute".
Why does this work (in my case)?
object attributes = typeof(Negate).GetCustomAttributes (true);
//Negate is one of the class in the lib
but this doesn't?
object attributes = type.GetCustomAttributes (true);
//type is one of the assembly.GetTypes()
I need to iterate though all the class in the library (as below).
When I say "doesn't work", I mean the cast following the GetCustomAttributes does or doesn't work.
Assembly assembly = Assembly.LoadFile (@"E:\IDEClassLibrary.dll");
foreach (Type type in assembly.GetTypes())
//object attributes = underType.GetCustomAttributes (true);
//object attributes = typeof(Negate).GetCustomAttributes (true);
//object attributes = type.GetCustomAttributes (true);