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);
//typeis one of the assembly.GetTypes()
I need to iterate though all the class in the library (as below).
=======================================================
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);}
Jess
C# Online.NET
http://wiki.csharp-online.net/

Attribute refuses cast
DonM
Thanks for your help, Mattias. The problem, unfortunately, was not in the code I showed. Rather, the problem was because I had my attribute class and my library classes in the same namespace; although, it eludes me why they require separate namespaces.
Jess
C# Online.NET
http://wiki.csharp-online.net/
Joe Gollner
See http://www.gotdotnet.com/team/clr/LoadFromIsolation.aspx for issues that can occur because you use Assembly.LoadFrom.