MSFN Forum: VB.NET Type error - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

VB.NET Type error Getting an error when running this code Rate Topic: -----

#1 User is offline   bobbert 

  • Newbie
  • Group: Members
  • Posts: 28
  • Joined: 16-May 05

Posted 19 May 2005 - 11:13 PM

im running a simple windows app with plugins, but in order for the plugins to work i first need this piece of code to work. In theory it should work fine but in practice... well not quite. I have a similar app with the exact same piece of code and all is working fine so im really confused.... the error is generated by the Bolded code, i think the error message is something like "not all types can be loaded". if anyone can solve this issue id really appreciate it. shot

Checks the specified directory for plugins of the correct type and then adds them to an array of availablePlugins
Public Shared Function findPlugins(ByVal pluginPath As String, ByVal pluginInterfaceName As String) As availablePlugin()
Dim plugins As New ArrayList
Dim pluginDLL() As String
Dim index As Integer
Dim objDLL As [Assembly]

'Go through all DLLs in the directory, attempting to load them
pluginDLL = Directory.GetFileSystemEntries(pluginPath, "*.dll")
For index = 0 To pluginDLL.Length - 1
MessageBox.Show(pluginDLL(index))
Try
objDLL = [Assembly].LoadFrom(pluginDLL(index))
examineAssembly(objDLL, pluginInterfaceName, plugins)
Catch e As Exception
MessageBox.Show("Debug")
'There has been an error in loading the DLL. No need to add any code here
End Try
Next

'Return all working plugins found
Dim pluginsFound(plugins.Count - 1) As availablePlugin

If plugins.Count <> 0 Then
plugins.CopyTo(pluginsFound)
Return pluginsFound
Else
Return Nothing
End If
End Function


'Check to see if the plugin implements the correct interface and if it does then add it to the list of availablePlugins
Private Shared Sub examineAssembly(ByVal objDLL As [Assembly], ByVal pluginInterfaceName As String, ByVal plugins As ArrayList)
Dim objType As Type
MessageBox.Show("1")
Dim objTypeA() As Type = objDLL.GetTypes
MessageBox.Show("2")
Dim objInterface As Type
Dim plugin As availablePlugin
'Go through all types in the DLL to see if they are the required type
Try
For Each objType In objTypeA
'We only want Public types since that is how our types are defined
If objType.IsPublic = True Then
'We dont want abstract classes so...
If Not ((objType.Attributes And TypeAttributes.Abstract) = TypeAttributes.Abstract) Then
'We want to see if it implements pluginInterface
objInterface = objType.GetInterface(pluginInterfaceName, True)

If Not (objInterface Is Nothing) Then
'Since it does implement pluginInterface we add it to our array of availablePlugins
plugin = New availablePlugin
plugin.pluginPath = objDLL.Location
plugin.pluginName = objType.FullName
plugins.Add(plugin)
End If
End If
End If
Next
Catch e As Exception
MessageBox.Show(e.Message)
End Try
End Sub


#2 User is offline   dman 

  • Friend of MSFN
  • PipPipPipPipPip
  • Group: Members
  • Posts: 717
  • Joined: 01-February 05

Posted 20 May 2005 - 08:48 AM

It would be more helpful if you attached your project to post so others can open it and look. If quoting error messages, you need to be exact, not "is something like".

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy