Retrieving Assembly Info

bpayne111

Junior Contributor
Joined
Feb 28, 2003
Messages
325
Location
BFE
I have a control which retrieves the Assembly Attributes and stores them.
When a user uses my control. I'd like to have it display the assembly info for the program that person is running.
As of now it will only display the assembly info that i created when i designed the control.
I've tried using the following code. When this code is finished executing... it returns "System.Windows.Forms.dll"
i'm looking for it to return the title of the program that owns this control.
Take note i am using the method System.Reflection.Assembly.GetCallingAssembly not GetExecutingAssembly.
GetExecutingAssembly returns my controls attributes instead.




C#:
public void GetAttributes()
{
Assembly asmInfo;
AssemblyTitleAttribute atrTitle;
//set assembly variables
				asmInfo = Assembly.Load(Assembly.GetCallingAssembly().GetName());
				objAttributes = asmInfo.GetCustomAttributes(false);
				//Convert from object to desired types
				//Select Case needed because order of attributes in array varies
				foreach(object objItem in objAttributes)
				{
					switch (objItem.GetType().ToString())
					{
						case "System.Reflection.AssemblyTitleAttribute":
						{
							atrTitle = (AssemblyTitleAttribute)objItem;
													lblInfo.Text = atrTitle.Title.ToString();	
							break;
						}
					}
}

is what i'm doing possible? it seems like there is a method somewhere to help me accomplish this
I'd really appreciate an answer on this one. This bug is really hurting the flexibility of the utility i'm writing.

brandon
 
Just created a simple solution 1 forms based app - went into assemblyinfo and gave it a title.
created a user control in a seperate project and pasted in your code.
Added a label to the control (lblInfo) and also a variable (object[] objAttributes;)
Added control to form and placed a button on form - in it's click event I called the GetAttributes method and the label displayed the applications title correctly.
How are you declaring objAttributes (or is that variable referenced anywhere else)?
What version of VS are you using (2003 here).
 
I'm using 2002
i must have left out the line
object[] objAttributes= asmInfo.GetCustomAttributes(false);
by accident.
I'm trying to use the GetAttributes method from the UserControl on an inherited form; and return the attributes of the project which has added the inherited form to it.
I sadly left this out before. I should have been more specific.
Now that i think about it the GetAttributes method should be in the inherited form instead... but i don't think it will make difference in what i'm trying to return. I'll try that out but i have a feeling it won't work either. i'd still like some more input on this subject if possible.
Thanks for your help.
brandon
 
The problem is solved... Congrats to microsoft for seeing my problem ahead of time :)

Assembly.GetENTRYAssembly was the key.
This returns the executing program's assembly not my controls
YAAAAAAY happy day all my work is not lost now.
 
Back
Top