0

I am writing a program and I want the program to support plugins. I created an interface that the program must implement. I am using the following code from my main program to call the plugin:

Dim asm As Assembly = Assembly.LoadFrom(ff.FullName)
' Get the type
Dim myType As System.Type = asm.GetType(asm.GetName.Name + "." + asm.GetName.Name)
' If the type is null then we try again without the root namespace name
If myType Is Nothing Then myType = asm.GetType(asm.GetName.Name)
' Check to see if the plugin implements the required Interface
Dim IsMyPlugin As Boolean = GetType(LGInterfaces.ILGSQLPlugin).IsAssignableFrom(myType)
Dim ActivePlugin As New PluginObject()
If IsMyPlugin Then
    ActivePlugin.Plugin = CType(Activator.CreateInstance(myType), LGInterfaces.ILGPlugin)

Every thing works and I am able to access my exposed properties, except for one problem I can not figure out. In my plugin, I use the following code to expose a property:

Private m_PanelObject As Windows.Forms.Control

Public Property PanelObject() As Windows.Forms.Control
Get
     Return m_PanelObject
End Get
Set(ByVal value As Windows.Forms.Control)
    m_PanelObject = value
End Set

Ok, so I set this property from my main program and everything works. Except, after a while, m_PanelObject gets set to Nothing for some odd reason. I'm not setting it to Nothing anywhere in my program and there is no place in the plugin code that sets it to Nothing. So what am I missing here? I am sure this will be pretty obvious. Thanks in advance

2
  • Can you provide a sample from your main program, specifically where the line where the exception is thrown? Commented May 25, 2009 at 7:56
  • The following line is being called from the main program: Plugin.Plugin.DataWriteHeader(FileWriter, "TestTable") This is a sub in the plugin. The plugin itself is where the exception is being thrown. Commented May 25, 2009 at 8:04

1 Answer 1

3

First, take a look at MEF because you're reinventing a wheel for no apparent reason.

As for your original question, make sure your plugin instance does not get disposed of or PanelObject is assigned Nothing or something of the kind: .NET Garbage Collector has nothing to do with this problem.

Sign up to request clarification or add additional context in comments.

2 Comments

The reason I'm not using MEF is because, as I understand it, it is targeted for .NET 3.5 or .NET 4.0. My application targets .NET 2.0
No, MEF can be used with .NET 2.0 as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.