getting the GUID from of a loaded assembly

  • Thread starter Thread starter Ron M. Newman
  • Start date Start date
R

Ron M. Newman

Hi: How do I get the GUID string out of an assembly? (I have it loaded and
referenced from an Assembly obect).
-Ron
 
This is an attribute in the Assembly Manifest. You get to it by getting an
instance of the System.Reflection.Assembly class, using:

System.Reflection.Assembly assembly = Assembly.GetExecutingAssembly();

Then you get an Attribute from the assembly using the
Assembly.GetCustomAttributes method:

((System.Runtime.InteropServices.GuidAttribute)assembly.GetCustomAttributes(
typeof(System.Runtime.InteropServices.GuidAttribute),false)[0]).Value

Note that you can use this method to get any of the various attributes in
the Assembly, as long as you know the type of the attribute, and what member
of the class you want to get at.

--
HTH,

Kevin Spencer
Microsoft MVP
Bit Player
http://unclechutney.blogspot.com

A pea rants as candy be sieving.
 
[assembly: Guid("6a6bf2ba-b251-492d-83c1-def446287453")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Using this method I am able to read "Guid", "AssemblyFileVersion", but NOT
"AssemblyVersion". Any ideas why that is? is it not going into the compiled
file?

I'm getting "index out of array" indicating this has not been found:

this.version =
((AssemblyVersionAttribute)this.myAssembly.GetCustomAttributes(typeof(AssemblyVersionAttribute),
false)[0]).Version;

-Ron

Kevin Spencer said:
This is an attribute in the Assembly Manifest. You get to it by getting an
instance of the System.Reflection.Assembly class, using:

System.Reflection.Assembly assembly = Assembly.GetExecutingAssembly();

Then you get an Attribute from the assembly using the
Assembly.GetCustomAttributes method:

((System.Runtime.InteropServices.GuidAttribute)assembly.GetCustomAttributes(
typeof(System.Runtime.InteropServices.GuidAttribute),false)[0]).Value

Note that you can use this method to get any of the various attributes in
the Assembly, as long as you know the type of the attribute, and what
member of the class you want to get at.

--
HTH,

Kevin Spencer
Microsoft MVP
Bit Player
http://unclechutney.blogspot.com

A pea rants as candy be sieving.

Ron M. Newman said:
Hi: How do I get the GUID string out of an assembly? (I have it loaded
and referenced from an Assembly obect).
-Ron
 
Ron,
Using this method I am able to read "Guid", "AssemblyFileVersion", but NOT
"AssemblyVersion". Any ideas why that is? is it not going into the compiled
file?

The AssemblyVersion gets special treatment as it becomes part of the
full assembly name. You can retrieve it with
myAssembly.GetName().Version.


Mattias
 
Use the GetName() method of the Assembly class to get this:

string name = assembly.GetName().Name;
string version = assembly.GetName().Version.ToString(4);

--
HTH,

Kevin Spencer
Microsoft MVP
Bit Player
http://unclechutney.blogspot.com

A pea rants as candy be sieving.

Ron M. Newman said:
[assembly: Guid("6a6bf2ba-b251-492d-83c1-def446287453")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Using this method I am able to read "Guid", "AssemblyFileVersion", but NOT
"AssemblyVersion". Any ideas why that is? is it not going into the
compiled file?

I'm getting "index out of array" indicating this has not been found:

this.version =
((AssemblyVersionAttribute)this.myAssembly.GetCustomAttributes(typeof(AssemblyVersionAttribute),
false)[0]).Version;

-Ron

Kevin Spencer said:
This is an attribute in the Assembly Manifest. You get to it by getting
an instance of the System.Reflection.Assembly class, using:

System.Reflection.Assembly assembly = Assembly.GetExecutingAssembly();

Then you get an Attribute from the assembly using the
Assembly.GetCustomAttributes method:

((System.Runtime.InteropServices.GuidAttribute)assembly.GetCustomAttributes(
typeof(System.Runtime.InteropServices.GuidAttribute),false)[0]).Value

Note that you can use this method to get any of the various attributes in
the Assembly, as long as you know the type of the attribute, and what
member of the class you want to get at.

--
HTH,

Kevin Spencer
Microsoft MVP
Bit Player
http://unclechutney.blogspot.com

A pea rants as candy be sieving.

Ron M. Newman said:
Hi: How do I get the GUID string out of an assembly? (I have it loaded
and referenced from an Assembly obect).
-Ron
 
Back
Top