[英]How to load same plugins from 2 different assemblies, and serializing and deserializing types between the two? C# .net
So I have two .net assemblies, one wpf the other a windows service. 所以我有两个.net程序集,一个是wpf,另一个是windows服务。 They talk using wcf with protobuf.net for serializing types.
他们使用wcf与protobuf.net进行对话,以便序列化类型。
Everything is working smooth however I just made a primitive plugin system that loads plugins, both assemblies in my project load THE SAME plugins with the intention of sending classes within them over the wire. 一切都工作顺利然而我只是制作了一个加载插件的原始插件系统,我的项目中的两个程序集加载了相同的插件,目的是通过网络发送类。
So... 1. WPF App loads, loads plugins (.net dlls) with Assembly.LoadFrom 2. WCF App loads plugins (same .net dlls) with Assembly.LoadFrom 3. Both assemblies share a dll (object library) that is explicitly referenced in source code. 所以...... 1. WPF App使用Assembly.LoadFrom加载,加载插件(.net dlls)2。WCF App使用Assembly.LoadFrom加载插件(相同的.net dll)3。两个程序集共享一个dll(对象库)在源代码中明确引用。
All types in Object Library can serialize on one end, go over the wire and deserialize no problem. 对象库中的所有类型都可以在一端进行序列化,遍历线路并反序列化没有问题。
Types in the plugins can be serialized on either end, but the other end throws a type not resolved exception when attempting to deserialize, even though they are the same type. 插件中的类型可以在任一端序列化,但另一端在尝试反序列化时抛出一个未解析的类型异常,即使它们是相同的类型。
Found out my problem, thanks shotgun for the willingness to help, it would have been a lot of code to show. 发现我的问题,感谢霰弹枪的意愿帮助,这将是很多代码展示。
Basically protobuf couldn't load the type because it didn't exist in the load context of the application domain. 基本上protobuf无法加载类型,因为它在应用程序域的加载上下文中不存在。 Read some stuff on MSDN had to handle the AppDomain.CurrentDomain.AssemblyResolve event and return the correct assembly for the plugin types.
阅读MSDN上的一些东西必须处理AppDomain.CurrentDomain.AssemblyResolve事件并返回插件类型的正确程序集。
如果您想加载插件程序集,那么MEF就是一个非常出色的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.