472,331 Members | 1,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

getting GUID attribute from assembly

I need to mark assemblies with a unique id (GUID in this case) and retrieve
it when the assembly is loaded into my application (a plug-in loader)... the
plug-in assembly all have a class in it which implements our plug-in base
class (which really is a default implementation of a interface IPlugin we
created)

The plug-in class looks like this

Imports bdb

Imports System.Runtime.InteropServices

<Guid("DD3196A0-60E2-4767-B1FE-D41B26B66A90")> _

Public Class SystemAdministration

Inherits bdb.pluginBaseClass

Private f_parentForm As bdb.frmMainWindow

Public Overrides ReadOnly Property name() As String

Get

Return "System Administration"

End Get

End Property

Public Sub New(ByVal parentForm As bdb.frmMainWindow, ByRef application As
Object)

f_parentForm = parentForm

End Sub

Public Overrides Sub StartPlugin()

Dim frmAdmin As New frmAdministration

frmAdmin.MdiParent = f_parentForm

frmAdmin.Show()

End Sub

End Class

=================================

then we have a loader function in our main application that does this, the
problem is at the line "Dim plugGUID As New Guid(CType(o_PluginInstance,
System.Runtime.InteropServices.GuidAttribute).Valu e)" where the cast is
invalid... how can i get the GUID off the assembly I loaded?! thanks!

====== code here for plug-in loader ==============

' s is a file listing of plug-ins in the directory the loader application
determined were good plug-ins

For Each s In al_goodPlugins

' start to load the plug-in

RaiseEvent PluginLoadStarted("Loading plug-in " & IO.Path.GetFileName(s) &
"...")

Try

' check to see if the dll's comments are saying it's a plugin

' load the file

Dim objAssembly As [Assembly] = [Assembly].LoadFile(s)

Dim classToUser As String = "BDBSDK." & Path.GetFileNameWithoutExtension(s)

' cast the assembly object into the IPlugin interface type

Dim o_PluginInstance As Object = objAssembly.CreateInstance(classToUser,
False, BindingFlags.CreateInstance, Nothing, aArgsList, Nothing, Nothing)

Dim plugGUID As New Guid(CType(o_PluginInstance,
System.Runtime.InteropServices.GuidAttribute).Valu e)

Dim plugIn As IPlugin = DirectCast(o_PluginInstance, IPlugin)

' if plugin is nothing then we didnt load for some reason

If plugIn Is Nothing Then

' name was plugin and it didn't load? something must of went wrong

MessageBox.Show("The plugin: " & Path.GetFileName(s) & " failed to load
properly", "Plug-in load error", MessageBoxButtons.OK,
MessageBoxIcon.Information)

Else

' if we got here the plugin load worked so far

' get name and an id for plugin plus the plugin object then add to arraylist

Dim pluginInfo As pluginInformation

pluginInfo.plugin = plugIn

pluginInfo.name = plugIn.name

pluginInfo.id = pluginCollection.Count ' since zero based index, the count
will always be the next id number of the array list

pluginCollection.Add(pluginInfo) ' add structure with plugin and info to the
plugin arraylist

End If

Catch ex As Exception

bdb.errorhandler.ErrorCaught(ex) ' we shouldn't get here, but if the plugin
is corrupt it will notify the user of it

End Try

Next
Nov 21 '05 #1
1 5317
I think I might of figured it out by changing a few lines to this

Dim o_PluginInstance As Object = objAssembly.CreateInstance(classToUser,
False, BindingFlags.CreateInstance, Nothing, aArgsList, Nothing, Nothing)

Dim plugGUID As Attribute =
Attribute.GetCustomAttribute(objAssembly.GetType(c lassToUser),
GetType(GuidAttribute))

Debug.WriteLine(String.Format("Loaded Plug-in GUID: {0}", CType(plugGUID,
GuidAttribute).Value))

Dim plugIn As IPlugin = DirectCast(o_PluginInstance, IPlugin)

"Brian Henry" <no****@nospam.com> wrote in message
news:O5**************@TK2MSFTNGP09.phx.gbl...
I need to mark assemblies with a unique id (GUID in this case) and retrieve
it when the assembly is loaded into my application (a plug-in loader)...
the plug-in assembly all have a class in it which implements our plug-in
base class (which really is a default implementation of a interface IPlugin
we created)

The plug-in class looks like this

Imports bdb

Imports System.Runtime.InteropServices

<Guid("DD3196A0-60E2-4767-B1FE-D41B26B66A90")> _

Public Class SystemAdministration

Inherits bdb.pluginBaseClass

Private f_parentForm As bdb.frmMainWindow

Public Overrides ReadOnly Property name() As String

Get

Return "System Administration"

End Get

End Property

Public Sub New(ByVal parentForm As bdb.frmMainWindow, ByRef application As
Object)

f_parentForm = parentForm

End Sub

Public Overrides Sub StartPlugin()

Dim frmAdmin As New frmAdministration

frmAdmin.MdiParent = f_parentForm

frmAdmin.Show()

End Sub

End Class

=================================

then we have a loader function in our main application that does this, the
problem is at the line "Dim plugGUID As New Guid(CType(o_PluginInstance,
System.Runtime.InteropServices.GuidAttribute).Valu e)" where the cast is
invalid... how can i get the GUID off the assembly I loaded?! thanks!

====== code here for plug-in loader ==============

' s is a file listing of plug-ins in the directory the loader application
determined were good plug-ins

For Each s In al_goodPlugins

' start to load the plug-in

RaiseEvent PluginLoadStarted("Loading plug-in " & IO.Path.GetFileName(s) &
"...")

Try

' check to see if the dll's comments are saying it's a plugin

' load the file

Dim objAssembly As [Assembly] = [Assembly].LoadFile(s)

Dim classToUser As String = "BDBSDK." &
Path.GetFileNameWithoutExtension(s)

' cast the assembly object into the IPlugin interface type

Dim o_PluginInstance As Object = objAssembly.CreateInstance(classToUser,
False, BindingFlags.CreateInstance, Nothing, aArgsList, Nothing, Nothing)

Dim plugGUID As New Guid(CType(o_PluginInstance,
System.Runtime.InteropServices.GuidAttribute).Valu e)

Dim plugIn As IPlugin = DirectCast(o_PluginInstance, IPlugin)

' if plugin is nothing then we didnt load for some reason

If plugIn Is Nothing Then

' name was plugin and it didn't load? something must of went wrong

MessageBox.Show("The plugin: " & Path.GetFileName(s) & " failed to load
properly", "Plug-in load error", MessageBoxButtons.OK,
MessageBoxIcon.Information)

Else

' if we got here the plugin load worked so far

' get name and an id for plugin plus the plugin object then add to
arraylist

Dim pluginInfo As pluginInformation

pluginInfo.plugin = plugIn

pluginInfo.name = plugIn.name

pluginInfo.id = pluginCollection.Count ' since zero based index, the count
will always be the next id number of the array list

pluginCollection.Add(pluginInfo) ' add structure with plugin and info to
the plugin arraylist

End If

Catch ex As Exception

bdb.errorhandler.ErrorCaught(ex) ' we shouldn't get here, but if the
plugin is corrupt it will notify the user of it

End Try

Next

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Razzie | last post by:
Hey all, I need to add a Guid to my class. In a tutorial I saw this was easy: class someClass { ... } However, I get the error "The type...
14
by: Nak | last post by:
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....
2
by: Brian Henry | last post by:
Is there anyway to retrieve the GUID code of an assembly for use in the application as a unique identifier? thanks!
9
by: Mis Dep. | last post by:
Dear all What is Create GUID on menu Tools in vb.net and how can i use it for something . as exsample Brg, TingN@ng
3
by: Jozef | last post by:
Hello, I apologize for such a newbie question, but I'd like to know if there's any way to reference the assembly GUID? Thanks!
2
by: Rob R. Ainscough | last post by:
I tried the following and it does provide a GUID, but not the GUID listed in the My Project ... Assembly Info button. Dim myAss As myAss =...
2
by: Troll | last post by:
Windows XP Pro VS 2005 & C# (I'm fairly new to C# but have doing VB.Net going on 2yrs and VB6 for 5yrs.) I'm using C# to build a custom RSS...
4
by: Ron M. Newman | last post by:
Hi: How do I get the GUID string out of an assembly? (I have it loaded and referenced from an Assembly obect). -Ron
2
by: PJ6 | last post by:
In VS.Net 2K3, a GUID use to be automatically included in the project's assemblyinfo.vb file: 'The following GUID is for the ID of the typelib...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.