不在deps.json文件中的程序集的Assembly.Load

时间:2019-01-07 11:25:03

标签: c# .net-core

我正在尝试加载程序集并从中动态创建类。这是代码:

assembly = Assembly.Load(assemblyName);
var type = assembly.GetType(assemblyName + ".MessageProcessor");
var processor = (IMessageProcessor)Activator.CreateInstance(type);
processor.Process();

问题是程序集名称属于项目中未引用的程序集。我将其手动部署到执行文件夹。

但是我收到此错误:

  

无法加载文件或程序集'AssemblyNameToLoad,Culture = neutral,   PublicKeyToken = null”。系统找不到指定的文件。

我无法将所有这些文件手动添加到deps.json。尽管没有出现在deps.json文件中,有没有办法制作.NET Core负载程序集?

1 个答案:

答案 0 :(得分:1)

LoadFrom should solve your problem as it loads a "physical" file.

I should add that you still have to communicate with it so some knowledge about it is prefereable, unless you want to go all reflection, so both loader and loaded should reference the same contract project.