fguihen Posted May 8, 2006 Posted May 8, 2006 (edited) i have an assembly loaded into my app. im trying to get at the attributes of this assembly so i have this code : foreach(Type OT in objDll.GetTypes()) { AssemblyTypeName[] custInfo = (AssemblyTypeName[])OT.GetCustomAttributes(false); } the problem is that i cant cast the return of "getCustomAttributes to an AssemblyTypeName array. i can get the return values when i use this: foreach(Type OT in objDll.GetTypes()) { Object [] custInfo = (AssemblyTypeName[])OT.GetCustomAttributes(false); } the problem is that when i try this: foreach( Object o in custInfo) { AssemblyTypeName atn = (AssemblyTypeName)o; atn.mycustomAttribute........ } i get an error here trying to cast the object to an AssemblyTypeName. what should i do? i can see my custom attribute and its value when i hover over the array and look at its contents , but i cant get to it. Just so youl know, assemblyTypeName is my own attribute that i created. i keep getting the error "unable to cast object of type "EmpManagment.AssemblyTypeName" to type "EmpManagment.AssemblyTypeName" Edited May 8, 2006 by fguihen Quote
fguihen Posted May 8, 2006 Author Posted May 8, 2006 found a solution. the Attribute and the class implementing the attribute were in the same namespace. once i put the attribute into a different namespace all worked. cant for the life of me think why it would have to be in a different namespace. could this be a bug?? if anyone can come up with an explination for why this is the case it would be great. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.