装配生成和类型问题(Assembly generation and types question)

编程入门 行业动态 更新时间:2024-10-05 17:24:01
装配生成和类型问题(Assembly generation and types question)

我的应用程序生成一个新类型Foo并将其写入新程序集。 然后我创建一个Foo类型的对象并序列化它。 如果我删除程序集并在我尝试反序列化Foo对象时重新创建它,它告诉我无法将类型Foo转换为Foo类型。 它认为那些是不同的类型。 有没有办法来解决这个问题?

编辑:我无法控制序列化。 编辑:我们发现版本guid总是不同的。 这个指南是什么以及我们如何指定它?

My app generates a new type Foo and writes it to new assembly. Then I create an object of type Foo and serialize it. If I delete the assembly and recreate it when I try to deserialize the Foo object it tells me that cannot convert type Foo to type Foo. It thinks those are different types. Is there a way to fix this?

EDIT: I have no control over the serialization. EDIT: We found that the version guid is always different. What is this guid and how we can specify it?

最满意答案

我认为当您使用二进制格式化程序时,模块版本ID(MVID)是在序列化中编写的。 当您想要反序列化时,它会使用该MVID搜索程序集中的类型。 这是坏事。 您无法控制MVID。 这是好事。 您可以打开dll文件,查找并替换您的MVID。 我通过使用十六进制编辑器更改MVID来测试它,它可以工作。

I think that the module version id (MVID) is written in the serialization when you use binary formatter. When you want to deserialize it searches for the type in assembly with that MVID. Here is the bad. You do not have control over MVID. Here is the good. You can open the dll file, find and replace the MVID with yours. I tested that by changing the MVID with hex editor and it works.

更多推荐

本文发布于:2023-08-07 16:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465245.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   Assembly   generation   types   question

发布评论

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

>www.elefans.com

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