简体   繁体   English

如何从2个不同的程序集加载相同的插件,并在两者之间序列化和反序列化类型? C#.net

[英]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.

相关问题 如何在不同文件夹中加载程序集C# - How to load assemblies in different folders C# 将二进制文件中的类型反序列化为不同应用程序(C#.NET)中的不同名称空间 - Deserializing types from binary file into different namespace in different app (C# .NET) 如何从两个不同的子文件夹将两个版本的相同程序集加载到两个不同的域中? - How can I load two versions of same assemblies into two different domains from two different subfolders? 如何在两种相同名称和内部结构之间进行转换,但是来自不同的程序集? - How to cast between 2 types of the same name and internal sturcture but from different assemblies? 将xml反序列化为c#对象并以不同的方式对其进行序列化 - deserializing an xml to c# object and serializing it in a different way C# 反思:如何加载不同文件夹中的多个程序集 - C# reflection: How to load multiple assemblies in different folders 如何从C#加载C ++程序集? - How to load c++ assemblies from c#? C#,反射,插件,程序集 - C#, reflection, plugins, assemblies 从C#序列化字体对象并在Java上反序列化 - Serializing Font Object from C# and Deserializing on Java C# - 从流中序列化/反序列化DES加密文件 - C# - Serializing/Deserializing a DES encrypted file from a stream
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM