System.Runtime.Serialization.SerializationException:找不到MyAssembly的组装

编程入门 行业动态 更新时间:2024-10-22 17:25:36
本文介绍了System.Runtime.Serialization.SerializationException:找不到MyAssembly的组装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以,我发现了一堆关于这一主题的线程,但我不认为我已经找到了一个适用呢。

基本上我的.exe负载由它来完成序列化和加载一个.dll(MyAssembly程序)文件。显然,序列化相当精细。

但是,当我去反序列化与此文章的标题错误爆炸MyAssembly.dll程序文件中的文件。

任何人有什么想法? !我不明白它怎么也找不到调用该代码的程序集

我的代码:

//反序列化 {无功斌=新System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); 无功的OBJ = bin.Deserialize(目标); 如果(的OBJ!= NULL) { ObjectToStore =(ObjectTypeInMyAssembly)目标文件; } }用 //连载(VAR的目标=新System.IO.FileStream(路径,System.IO.FileMode.OpenOrCreate)) {无功斌=新System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); bin.Serialize(目标,ObjectToStore); }

解决方案

是相同的DLL文件夹像EXE?结果我明白你的序列化/反序列化生活中的DLL(MyAssembly程序)一个对象。当反序列化,格式化器确定从序列化的数据的类型的名称,并试图找到这种类型的在主可执行文件夹的组件,即是 - EXE文件夹。结果,溶液 - 该DLL移到EXE夹。有一种方法使格式化到另一个程序集搜索,捕获事件 AppDomain.AssemblyResolve 并返回你的DLL。请参见 MSDN 。

So I've found a bunch of threads on this topic but I don't think I've found one that applies yet.

Basically my .exe loads a .dll (MyAssembly) file which does the serialization and loading. Obviously it serializes quite fine.

But when I go to deserialize the file within the MyAssembly.dll file it explodes with the error in the title of this post.

Anyone have any ideas? I don't understand how it can't find the assembly that is calling the code!

My code:

// deserialize using (var target = new System.IO.FileStream(Path, System.IO.FileMode.OpenOrCreate)) { var bin = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); var Obj = bin.Deserialize(target); if (Obj != null) { ObjectToStore = (ObjectTypeInMyAssembly)Obj; } } // serialize using (var target = new System.IO.FileStream(Path, System.IO.FileMode.OpenOrCreate)) { var bin = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); bin.Serialize(target, ObjectToStore); }

解决方案

Is the DLL in the same folder like the EXE? I see you serialize/deserialize a object that lives in the DLL ("MyAssembly"). When deserialize, the formatter determines the name of the type from serialized data, and tries to find this type in the assembly at the main executable folder, that is- EXE folder. Solution- move the DLL to EXE folder. There is a way to cause the formatter to search in another assembly, capture the event AppDomain.AssemblyResolve and return your DLL. See MSDN.

更多推荐

System.Runtime.Serialization.SerializationException:找不到MyAssembly的组装

本文发布于:2023-11-10 02:21:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574078.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   Runtime   System   Serialization   MyAssembly

发布评论

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

>www.elefans.com

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