Retrieving Assembly Info

bpayne111

Well-known member
Joined
Feb 28, 2003
Messages
326
Location
BFE
I have a control which retrieves the Assembly Attributes and stores them.
When a user uses my control. Id 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.
Ive tried using the following code. When this code is finished executing... it returns "System.Windows.Forms.dll"
im 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 im doing possible? it seems like there is a method somewhere to help me accomplish this
Id really appreciate an answer on this one. This bug is really hurting the flexibility of the utility im 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 its 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).
 
Im using 2002
i must have left out the line
object[] objAttributes= asmInfo.GetCustomAttributes(false);
by accident.
Im 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 dont think it will make difference in what im trying to return. Ill try that out but i have a feeling it wont work either. id 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 programs assembly not my controls
YAAAAAAY happy day all my work is not lost now.
 
Back
Top