有我的示例代码
public interface ICommonInterface
{
Task<T> SomeMethod<T>(string params) where T : new();
}
public class ExternalAssembly : ICommonInterface
{
public ExternalAssembly(string params) {...}
public async Task<T> SomeMethod<T>(string params) where T : new() {...}
}
因此,我正在从另一个引用ICommonInterface
的项目中加载程序集。我有以下代码,在最后一步失败
object assemblyInstance;
Assembly assembly;
assembly = Assembly.LoadFile(assemblyFile);
Type type = assembly.GetType("Namespace.ExternalAssembly");
assemblyInstance = Activator.CreateInstance(type, new[] { params });
var myClass = (assemblyInstance as ICommonInterface);
问题是myClass
为空
以前的代码版本可以正常工作,就在这里(只有界面有所不同)
public interface ICommonInterface
{
Task<SomeClass> SomeMethod(string params);
}
public class ExternalAssembly : ICommonInterface
{
public ExternalAssembly(string params) {...}
public async Task<SomeClass> SomeMethod(string params) {...}
}