BinaryFormatter.反序列化“无法找到程序集"在ILMerge之后

编程入门 行业动态 更新时间:2024-10-10 05:16:36
本文介绍了BinaryFormatter.反序列化“无法找到程序集"在ILMerge之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个带有引用的dll的C#解决方案(也是具有相同.Net版本的C#).当我构建解决方案并运行生成的exe而不合并exe和所引用的dll时,一切正常.

I have a C# solution with a referenced dll (also C# with the same .Net version). When I build the solution and run the resulting exe, without merging the exe and the referenced dll, everything works fine.

现在,我想将这些合并为一个exe.我运行ILMerge,一切似乎都正常.我尝试执行该exe文件,在它试图反序列化引用的dll中定义的对象之前,它似乎运行得很好.

Now I want to merge these into one exe. I run ILMerge and everything appears to work ok. I try to execute the exe and it seems to run just fine until it tries to deserialize an object defined in the referenced dll.

using (Stream fstream = new FileStream(file_path, FileMode.Open)) { BinaryFormatter bf = new BinaryFormatter(); return bf.Deserialize(fstream) as ControlledRuleCollection; // throws unable to find assembly exception }

这里可能缺少一些ILMerge选项吗?

Is there maybe some ILMerge option I'm missing here?

推荐答案

听起来您已经在DLL中序列化了一个对象,然后将所有程序集与ILMerge合并,现在正尝试对该对象进行反序列化.这根本行不通.二进制序列化的反序列化过程将尝试从原始DLL加载对象的类型.此DLL在ILMerge之后不存在,因此反序列化将失败.

It sounds like you've serialized an object inside a DLL, then merged all of the assemblies with ILMerge and are now trying to deserialize that object. This simply won't work. The deserialization process for binary serialization will attempt to load the object's type from the original DLL. This DLL doesn't exist post ILMerge and hence the deserialization will fail.

序列化和反序列化过程都需要在合并之前或之后进行操作.不能混在一起

The serialization and deserialization process need to both operate pre or post merge. It can't be mixed

更多推荐

BinaryFormatter.反序列化“无法找到程序集"在ILMerge之后

本文发布于:2023-11-13 06:09:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583655.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列化   程序   BinaryFormatter   quot   ILMerge

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!