【发布时间】:2009-05-25 07:49:00
【问题描述】:
我正在编写一个程序,我希望该程序支持插件。我创建了一个程序必须实现的接口。我正在使用我的主程序中的以下代码来调用插件:
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)
一切正常,我可以访问我公开的属性,除了一个我无法弄清楚的问题。在我的插件中,我使用以下代码来公开一个属性:
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
好的,所以我从我的主程序中设置了这个属性,一切正常。除了,过了一会儿,m_PanelObject 出于某种奇怪的原因被设置为 Nothing。我没有在程序中的任何地方将其设置为 Nothing,插件代码中也没有将其设置为 Nothing 的位置。那么我在这里错过了什么?我相信这将是非常明显的。提前致谢
【问题讨论】:
-
您能否提供一个来自您的主程序的示例,特别是抛出异常的行的位置?
-
从主程序调用以下行: Plugin.Plugin.DataWriteHeader(FileWriter, "TestTable") 这是插件中的一个子程序。插件本身就是引发异常的地方。
标签: c# .net vb.net assemblies