Jump to content
Xtreme .Net Talk

Type.AssemblyTypeName . having problems getting to my custom attribute


Recommended Posts

Posted (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 by fguihen
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...