By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

Assembly GUID

P: n/a
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!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
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



"Nak" <a@a.com> wrote in message
news:Or**************@tk2msftngp13.phx.gbl...
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!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

Nov 20 '05 #2

P: n/a
Nak
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!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"Thomas" <no****@nospam.nospam> wrote in message
news:uy**************@tk2msftngp13.phx.gbl...
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



"Nak" <a@a.com> wrote in message
news:Or**************@tk2msftngp13.phx.gbl...
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!

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\


Nov 20 '05 #3

P: n/a
Nak
Sorry, Hi again,

I have found that using the following obtains a GUID

System.Reflection.Assembly.GetExecutingAssembly.Ge tType.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" <a@a.com> wrote in message
news:OQ*************@tk2msftngp13.phx.gbl...
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!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ "Thomas" <no****@nospam.nospam> wrote in message
news:uy**************@tk2msftngp13.phx.gbl...
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



"Nak" <a@a.com> wrote in message
news:Or**************@tk2msftngp13.phx.gbl...
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!

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\



Nov 20 '05 #4

P: n/a
"Nak" <a@a.com> schrieb
Sorry, Hi again,

I have found that using the following obtains a GUID
System.Reflection.Assembly.GetExecutingAssembly.Ge tType.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

--
Armin

Nov 20 '05 #5

P: n/a
Nak
>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!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #6

P: n/a
Nak
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!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

--
Armin

Nov 20 '05 #7

P: n/a
Nak
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" <az*******@freenet.de> wrote in message
news:Op*************@TK2MSFTNGP09.phx.gbl...
"Nak" <a@a.com> schrieb
Sorry, Hi again,

I have found that using the following obtains a GUID
System.Reflection.Assembly.GetExecutingAssembly.Ge tType.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

--
Armin

Nov 20 '05 #8

P: n/a
"Nak" <a@a.com> schrieb:
As a matter of interest, why the "[]" square braces around the
declarations, what does it do? Thanks in advance.


http://msdn.microsoft.com/library/en...amesincode.asp

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #9

P: n/a
"Nak" <a@a.com> schrieb
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.
Nov 20 '05 #10

P: n/a
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> schrieb

http://msdn.microsoft.com/library/en...amesincode.asp

_That's_ the one I was looking for.

;-)
--
Armin

Nov 20 '05 #11

P: n/a
"Armin Zingler" <az*******@freenet.de> schrieb:
http://msdn.microsoft.com/library/en...amesincode.asp
_That's_ the one I was looking for.


It's really hard to find...

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #12

P: n/a
Nak
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" <az*******@freenet.de> wrote in message
news:ur**************@TK2MSFTNGP10.phx.gbl...
"Nak" <a@a.com> schrieb
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.

Nov 20 '05 #13

P: n/a
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."

Nov 20 '05 #14

P: n/a
Nak
> 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
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.