473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 5410
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 or namespace name 'Guid' could not be found (are...
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 = .GetEntryAssembly Dim myAssGUID As System.Guid =...
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 generator. I'm having trouble building the guid...
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 if this project is exposed to COM <Assembly:...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.