Dynamically Loading .NET Assemblies

I am writing a program and want the program to support plugins. I have created an interface that the program should 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)

      

Everything works and I can access my exposed properties except for one problem that I can't figure out. In my plugin, I am using the following code to expose the 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 that after a while, m_PanelObject gets Nothing for some odd reason. I don't set it 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'm sure this will be pretty obvious. thanks in advance

0


a source to share


1 answer


First, check out MEF because you are reinventing the wheel for no apparent reason.



Regarding your original question, make sure your plugin instance is not being removed or PanelObject

assigned Nothing

or something like that: .NET Garbage Collector has nothing to do with this issue.

+3


a source







All Articles