473,748 Members | 10,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to create\use plugins causes casting issue.

I am creating a application that will be using plugins. I am doing this so that when I want to let this application work with another type of dbase system, I only have to write\install one plugin, not the entire app.

I have created a base interface, it looks like:

public interface myModel
sub Initialize(byre f DisplayPanel)
sub Connect()
sub Disconnect()
sub Query()
...
end interface
I have created 3 projects. The container, the plugin and the model. I have put this interface file in all three projects. The third project does not do anything, but stores the model for me.
I have created a plugin, it lookes like:

public class myPlugin1
implements myModel

private dbConn as ???? - this is an object of perticular type.
private ResultCount as long
private isConnected as boolean

public sub Initialize(byre f DisplayPanel as panel) implements myModel.Initial ize
....
end sub

(and so forth)
end class

I build this as a DLL.

I then make my "container" application. I use the following code to load\test for my plugins:

Public Class PluginServices

Public Structure AvailablePlugin
Public AssemblyPath As String
Public ClassName As String
End Structure

Public Shared Function FindPlugins(ByV al strPath As String, ByVal strInterface As String) As AvailablePlugin ()
Dim Plugins As ArrayList = New ArrayList
Dim strDLLs() As String, intIndex As Integer
Dim objDLL As [Assembly]

'Go through all DLLs in the directory, attempting to load them
strDLLs = Directory.GetFi leSystemEntries (strPath, "*.dll")
For intIndex = 0 To strDLLs.Length - 1
Try
objDLL = [Assembly].LoadFrom(strDL Ls(intIndex))
ExamineAssembly (objDLL, strInterface, Plugins)
Catch e As Exception
'Error loading DLL, we don't need to do anything special
End Try
Next

'Return all plugins found
Dim Results(Plugins .Count - 1) As AvailablePlugin

If Plugins.Count <> 0 Then
Plugins.CopyTo( Results)
Return Results
Else
Return Nothing
End If
End Function

Private Shared Sub ExamineAssembly (ByVal objDLL As [Assembly], ByVal strInterface As String, ByVal Plugins As ArrayList)
Dim objType As Type
Dim objInterface As Type
Dim Plugin As AvailablePlugin

'Loop through each type in the DLL
For Each objType In objDLL.GetTypes
'Only look at public types
If objType.IsPubli c = True Then
'Ignore abstract classes
If Not ((objType.Attri butes And TypeAttributes. Abstract) = TypeAttributes. Abstract) Then

'See if this type implements our interface
objInterface = objType.GetInte rface(strInterf ace, True)

If Not (objInterface Is Nothing) Then
'It does
Plugin = New AvailablePlugin
Plugin.Assembly Path = objDLL.Location
Plugin.ClassNam e = objType.FullNam e
Plugins.Add(Plu gin)
End If

End If
End If
Next
End Sub

Public Shared Function CreateInstance( ByVal Plugin As AvailablePlugin ) As Object
Dim objDLL As [Assembly]
Dim objPlugin As Object

Try
'Load dll
objDLL = [Assembly].LoadFrom(Plugi n.AssemblyPath)

'Create and return class instance
objPlugin = objDLL.CreateIn stance(Plugin.C lassName)
Catch e As Exception
Return Nothing
End Try

Return objPlugin
End Function

End Class
I then try to connect to my plugin later in my "container" application. I do this with:
Private Sub lstSourceSystem _SelectedIndexC hanged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles lstSourceSystem .SelectedIndexC hanged
' Here we connect to the ImportControlle r and show its connection properties
Try
Dim tmpControl As SourceModel
Dim dblResult As Double
**>> tmpControl = DirectCast(Plug inServices.Crea teInstance(Plug ins(lstSourceSy stem.SelectedIn dex)), myModel)

tmpControl.Init ialize(objHost)

frmSystemConnec tion.Show()

tmpControl.Show Interface(Me.fr mSystemConnecti on)

Catch ex As Exception
MsgBox(ex.Messa ge)
frmSystemConnec tion.Hide()
ImportControl = Nothing
End Try
End Sub

I get a cast error on the line starting with **>>
I have tried just using CAST, and tried not using any type of casting. same results.
What am I missing. I have been searching the internet, and I have found examples of how I should do this, but I keep getting the same results.

--------------------------------
From: Greg Conely

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>OUzq1+c3Z0S igQG9wJ15AQ==</Id>
Nov 20 '05 #1
0 1600

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

Similar topics

4
4203
by: stu_pb | last post by:
I am designing a plugin system for a window application using .NET(C# specifically). One of the requirements of the plugin system is to be able to dynamically load/unload plugins. My initial thought was to use System.Reflection.Assembly.Load to load the plugins dynamically. This worked great, but I was left with no way to dynamically unload the plugin. So now I come to creating a new AppDomain for the plugins to reside in, since the...
5
1460
by: ThunderMusic | last post by:
Hi, I have some code to load some plug-ins, but the code requires me to know the name of the class to load (here: SamplePlugin, derived from IPlugin) : (Here is some C# code, but I use VB.Net to code my program) using System; using System.Reflection; public class Driver {
5
3183
by: Christoph Haas | last post by:
Dear coders... I'm working on an application that is supposed to support "plugins". The idea is to use the plugins as packages like this: Plugins/ __init__.py Plugin1.py Plugin2.py Plugin3.py
7
3677
by: yufufi | last post by:
lets say we have a 'shape' class which doesn't implement IComparable interface.. compiler doesn't give you error for the lines below.. shape b= new shape(); IComparable h; h=(IComparable)b; but it complains for the following lines
5
1833
by: Mike D Sutton | last post by:
Hi, I'm porting an old project over to C# which makes heavy use of plugins, however I'm not sure the way I've approached it is the best technique. In the old project, I had a TypeLib with the global interfaces each plugin needed to expose defined with it, then referenced this within each plugin. In the C# version I currently have a DLL defined which simply exposes the interfaces, and each plugin project references this file. Is there any...
3
1664
by: Eric_Dexter | last post by:
I am having trouble trying to reuse the code that was provided in the wxdemo package of wxpython. The program I am trying to use parts of is Grid_MegaExample.py thier code is class MegaTable(Grid.PyGridTableBase): """ A custom wx.Grid Table using user supplied data """ def __init__(self, data, colnames, plugins): """data is a list of the form
1
2085
by: krach.aran | last post by:
I'm creating a winforms click-once application that is plugin enabled. The application is working, and so are the plugins. but now i have got the following problem: after deployment i do not want to touch _ANY_ file of my deployment, but i have got one directory that contains all the plugins. As soon as the application starts i want to get all these dll's and hook them up to the main application.
1
8822
by: Arif Mohammed | last post by:
Hi, iam using MySql 4.0.1 and jboss-4.0.4.GA Iam getting the following exception when there are more concurrent requests more than 50 in a second Caused by: org.xyz.MyClass: SQL Exception:Deadlock found when trying to get lock; Try restarting transaction, message from server: "Lock wait timeout exceeded; Try restarting transaction" at com.xyz.retrieveDetails(MySessionBean.java:679) at...
2
1315
by: Michel Couche | last post by:
Hello, Normally automatic converters do a very good job at translating code between C# and VB I have a specific issue however that I can not solve using these converters .... and I just can not figure out how to do it myself. The line that causes problem is: : <%# ((AuthorizationRule) Container.DataItem).Action %>
0
8989
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.