System.Runtime.Serialization.SerializationException:找不到MyAssembly的组装 [英] System.Runtime.Serialization.SerializationException: Unable to find assembly MyAssembly

查看:2576
本文介绍了System.Runtime.Serialization.SerializationException:找不到MyAssembly的组装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



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



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



我的代码:

  
$ b使用(VAR的目标=新System.IO.FileStream(路径,System.IO.FileMode.OpenOrCreate))$> //反序列化
{
无功斌=新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的组装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆