【发布时间】:2012-12-20 14:19:48
【问题描述】:
我有一个应用程序,我想在其中实例化一个完全在应用程序之外的类,可能是在以后由第三方编写的。所以类不能知道,但类中的接口是已知的。所以我想使用后期绑定。
在我的代码 (VB.NET) 中,我有以下内容:
Dim a As Object
a = Activator.CreateInstance("MyNameSpace.CustomClass", "")
MsgBox(a.Name)
我在第二行出现异常:Could not load file or assembly 'MyNameSpace.CustomClass' or one of its dependencies. The system cannot find the file specified.,即使程序集与可执行文件位于同一文件夹中。我不能使用 Type.GetType(),因为调用程序集不知道该类型。
【问题讨论】:
标签: vb.net instantiation late-binding