简体   繁体   English

C#-对父程序集引用的动态加载的程序集访问

[英]C# - Dynamically Loaded Assembly Access To Parent Assembly References

I am trying to implement a plug-in style architecture. 我正在尝试实现插件样式的体系结构。 There are core, external libraries used by both the plug-ins, and in the main application. 插件和主应用程序都使用核心的外部库。 A good example of such library is JSON.NET. 此类库的一个很好的示例是JSON.NET。

As I develop plug-ins, I make reference to the same JSON.NET version referenced in the main application. 在开发插件时,我引用了主应用程序中引用的相同JSON.NET版本。 When the plug-in is compiled, I have not been merging the external libraries with the plug-in, as I expected the references to resolve to the same assemblies loaded by the main application. 编译插件时,我尚未将外部库与插件合并,因为我希望引用能够解析为与主应用程序加载的相同程序集。

However, this isn't working. 但是,这不起作用。 When I try to invoke methods of the plug-in in the main application, I am getting "could not load assembly..." error. 当我尝试在主应用程序中调用插件的方法时,出现“无法加载程序集...”错误。

How to go about making the dynamically loaded plugins resolve references the main application's references? 如何使动态加载的插件解析主应用程序的引用?

A few considerations: 一些注意事项:

  • Design your architecture in a way that you don't need the internal references from the core system. 以不需要核心系统内部引用的方式设计架构。 At Example you could create wrapper for the needed functions in the core which can be used in the plugins. 在示例中,您可以为核心中所需的功能创建包装器,这些包装器可以在插件中使用。
  • in case of .NET 4.0+: unsing the dynamic keyword 如果是.NET 4.0+:取消对dynamic关键字的设置
  • using Reflection 使用反射
  • Runtimecompiling 运行时编译

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM