프로그램을 작성 중이므로 프로그램에서 플러그인을 지원해야합니다. 프로그램에서 구현해야하는 인터페이스를 만들었습니다. 나는 플러그인을 호출하는 내 주요 프로그램에서 다음 코드를 사용하고 있습니다 :.NET 어셈블리를 동적으로로드
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으로 설정하는 플러그인 코드의 위치가 없습니다. 그래서 나는 무엇을 여기에서 놓치고 있냐? 나는 이것이 꽤 명백 할 것이라고 확신한다. 미리 감사드립니다.
주 프로그램에서 샘플을 제공 할 수 있습니까? 특히 예외가 발생한 행은 어디에서 제공 할 수 있습니까? – Galilyou
주 프로그램에서 다음 행이 호출됩니다. Plugin.Plugin.DataWriteHeader (FileWriter, "TestTable") 이것은 플러그인의 하위 프로그램입니다. 플러그인 자체는 예외가 던져지는 곳입니다. –