Assembly GUID

  • Thread starter Thread starter Nak
  • Start date Start date
N

Nak

Hi there,

Does anyone know how I would get the value of the assembly GUID in code
from within the same application? Thanks in advance.

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Slow internet connection?
Having problems with you job?
You're marriage is on the rocks?
You can't sleep at night?
You have a drink and drugs addiction?
You are sexually impotent?
Then enable Option Strict!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Hi Nick,
you can get most Assembly info from the System.Reflection namespace.
You get the current domain from the AppDomain type, then get the list of
assemblies from it. When you find the assembly that you are looking for (the
list contains all the system assemblies as well), check the referenced
assemblies for that one assembly - the referenced assembly is of type
AssemblyName, and you can get a load of info from that. I'm not sure about
the GUID, but it as a PublicKeyToken property, which may be what you are
looking for....

Here's some code to get you started:

Dim ad As AppDomain

Dim ass As System.Reflection.Assembly

Dim add() As System.Reflection.Assembly = ad.CurrentDomain.GetAssemblies()

Dim addRef() As System.Reflection.AssemblyName

Dim addRefItem As System.Reflection.AssemblyName

For Each ass In add

If ass.ToString.Substring(0, 5).ToUpper = "THE APP NAME" Then

addRef = ass.GetReferencedAssemblies

For Each addRefItem In addRef



Next

Next
 
Hi Thomas,

Thanks for your help, the GUID that I am after is actually the one that is
exposed to COM, if you take a look in the AssemblyInfo.vb file you will see
the lines,

'The following GUID is for the ID of the typelib if this project is exposed
to COM
<Assembly: Guid(" GUID goes in here ")>

I am after getting this GUID programatically. I thought it might be in the
application object, as is everything else that is in the Assembly file but
it isn't. I want to use it for making toolbar and menu buttons for Internet
Explorer, and for this you need to provide a GUID. I didn't want to just
use a randomly generated GUID just incase it had been used perviously
(though I am not sure of the chances of this happening are). So I thought
if I use my applications GUID this would solve all problems. I'm short of
copying an pasting but I don't like canning things like that.

Thanks for your help though, any ideas on the above?

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Slow internet connection?
Having problems with you job?
You're marriage is on the rocks?
You can't sleep at night?
You have a drink and drugs addiction?
You are sexually impotent?
Then enable Option Strict!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Sorry, Hi again,

I have found that using the following obtains a GUID

System.Reflection.Assembly.GetExecutingAssembly.GetType.GUID.ToString

But the GUID returns is not identical to the one in the AssemblyInfo
file, but, this may still be what I am after. Any idea why this GUID is
different? Thanks again.

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Slow internet connection?
Having problems with you job?
You're marriage is on the rocks?
You can't sleep at night?
You have a drink and drugs addiction?
You are sexually impotent?
Then enable Option Strict!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Nak said:
Sorry, Hi again,

I have found that using the following obtains a GUID


System.Reflection.Assembly.GetExecutingAssembly.GetType.GUID.ToString


But the GUID returns is not identical to the one in the
AssemblyInfo
file, but, this may still be what I am after. Any idea why this GUID
is different? Thanks again.


Imports System.Reflection
Imports System.Runtime.InteropServices

'...

Dim assy As [Assembly]
Dim Attributes As Object()

assy = [Assembly].GetExecutingAssembly
Attributes = assy.GetCustomAttributes(GetType(GuidAttribute), False)

If Attributes.Length = 0 Then
MsgBox("no guid attribute")
Else
MsgBox(DirectCast(Attributes(0), GuidAttribute).Value)
End If
 
Unfortunately, pervious use of GUIDs is becoming increasingly common.

LOL! You know what I meant haha :-)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Slow internet connection?
Having problems with you job?
You're marriage is on the rocks?
You can't sleep at night?
You have a drink and drugs addiction?
You are sexually impotent?
Then enable Option Strict!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Thank you very much Armin :-)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Slow internet connection?
Having problems with you job?
You're marriage is on the rocks?
You can't sleep at night?
You have a drink and drugs addiction?
You are sexually impotent?
Then enable Option Strict!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
As a matter of interest, why the "[]" square braces around the declarations,
what does it do? Thanks in advance.

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Slow internet connection?
Having problems with you job?
You're marriage is on the rocks?
You can't sleep at night?
You have a drink and drugs addiction?
You are sexually impotent?
Then enable Option Strict!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Armin Zingler said:
Nak said:
Sorry, Hi again,

I have found that using the following obtains a GUID


System.Reflection.Assembly.GetExecutingAssembly.GetType.GUID.ToString


But the GUID returns is not identical to the one in the
AssemblyInfo
file, but, this may still be what I am after. Any idea why this GUID
is different? Thanks again.


Imports System.Reflection
Imports System.Runtime.InteropServices

'...

Dim assy As [Assembly]
Dim Attributes As Object()

assy = [Assembly].GetExecutingAssembly
Attributes = assy.GetCustomAttributes(GetType(GuidAttribute), False)

If Attributes.Length = 0 Then
MsgBox("no guid attribute")
Else
MsgBox(DirectCast(Attributes(0), GuidAttribute).Value)
End If
 
Nak said:
As a matter of interest, why the "[]" square braces around the
declarations, what does it do? Thanks in advance.

Assembly is a VB keyword. To distinguish between the keyword and the data
type, the braces are used.

see also:
<F1>
Visual Studio.NET
Visual Basic and Visual C#
Reference
Visual Basic language
Visual Basic Language Tour
Features
Declared elements
Name of declared elements

Direct link (VS 2003):
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB/vbcn7/html/vbconElementNames.htm

(see hints in signature)


--
Armin

- Links might be split into two lines. Concatenate them using notepad.
- Links might require to add a ".nnnn" after the "2003FEB", e.g.
"2003FEB.1033" for localized versions.
- Links starting with "ms-help" are URLs for the document explorer (<F1>).
Paste them in the URL textbox and press enter. Using internal help (menu
tools -> options -> environment -> help), display the "Web" toolbar that
contains the textbox.
- The tree representing the table of contents has been translated from
localized (German) version. Excuse slight deviations.
 
Thanks loads Armin :-)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Slow internet connection?
Having problems with you job?
You're marriage is on the rocks?
You can't sleep at night?
You have a drink and drugs addiction?
You are sexually impotent?
Then enable Option Strict!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Armin Zingler said:
Nak said:
As a matter of interest, why the "[]" square braces around the
declarations, what does it do? Thanks in advance.

Assembly is a VB keyword. To distinguish between the keyword and the data
type, the braces are used.

see also:
<F1>
Visual Studio.NET
Visual Basic and Visual C#
Reference
Visual Basic language
Visual Basic Language Tour
Features
Declared elements
Name of declared elements

Direct link (VS 2003):
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB/vbcn7/html/vbconElementNames.htm

(see hints in signature)


--
Armin

- Links might be split into two lines. Concatenate them using notepad.
- Links might require to add a ".nnnn" after the "2003FEB", e.g.
"2003FEB.1033" for localized versions.
- Links starting with "ms-help" are URLs for the document explorer (<F1>).
Paste them in the URL textbox and press enter. Using internal help (menu
tools -> options -> environment -> help), display the "Web" toolbar that
contains the textbox.
- The tree representing the table of contents has been translated from
localized (German) version. Excuse slight deviations.
 
Thanks for Armin's codes,

Nick, the GUID you got in from these codes is actually the GUID of the
System.Reflection.Assembly type, not the GUID for you assembly. So it's
different from the GUID in the AssemblyInfo.vb file.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Nick, the GUID you got in from these codes is actually the GUID of the
System.Reflection.Assembly type, not the GUID for you assembly. So it's
different from the GUID in the AssemblyInfo.vb file.

Aah, thanks for the info. I've got a nice little routine that gets the
applications GUID now, just what I wanted. :-)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Back
Top