简体   繁体   English

在二进制序列化期间更改程序集名称

[英]Change Assembly Name during Binary Serialization

Let me briefly explain my architecture before I ask my question. 在提出问题之前,让我简要解释一下我的体系结构。 I have a client application that calls out to a web service and passes it a couple of items of data. 我有一个客户端应用程序,它可以调用Web服务并将其传递几个数据项。 The web service uses this data to do some lookups and then returns a binary serialized object, by using the BinaryFormatter, as a byte array to the client. Web服务使用此数据进行一些查找,然后使用BinaryFormatter将二进制序列化的对象作为字节数组返回给客户端。 The client then deserializes the object and uses it. 然后,客户端反序列化对象并使用它。 My problem is I had to rename the assembly that the server uses for the new version. 我的问题是我必须重命名服务器用于新版本的程序集。 This has caused a problem when deserializing in the client. 在客户端反序列化时,这引起了一个问题。 It is not an option for me to deploy a new client just so the new assembly name can be used so my question is, is there a way I can change the Assembly Name that is being written during serialization. 我不能选择部署新的客户端,只是为了可以使用新的程序集名称,所以我的问题是,有没有办法我可以更改序列化过程中编写的程序集名称。 I know how to use SerializationBinders for deserializing but that does not solve my problem as that would require deploying a new client. 我知道如何使用SerializationBinders进行反序列化,但这不能解决我的问题,因为这将需要部署新客户端。

I am currently using C# 2.0 for both the win forms application and the web service. 我目前正在将C#2.0用于Win Forms应用程序和Web服务。

You can recreate an empty assembly with the old name containing just the AssemblyInfo.cs, where you put a type redirect: [assembly: TypeForwardedTo(typeof(MyClassName))], for every type that is moved to another assembly. 您可以使用仅包含AssemblyInfo.cs的旧名称重新创建一个空程序集,并在其中放置类型重定向:[assembly:TypeForwardedTo(typeof(MyClassName))],用于移到另一个程序集的每种类型。 Ofc this assembly should reference the new one. 大会办公厅应参考新的大会。

But generally consider not using binary serialization for complex data structures, because it's not friendly to such changes as moving types between assemblies. 但是通常考虑不要对复杂的数据结构使用二进制序列化,因为它对诸如在程序集之间移动类型之类的更改并不友好。

If I were using .NET 4 the solution from Thomas would have been perfect. 如果我使用的是.NET 4,那么Thomas的解决方案将是完美的。 However, .NET 2.0 does not provide this functionality. 但是,.NET 2.0不提供此功能。 Instead I just renamed the dlls back to what they were. 相反,我只是将dll重命名为它们。 I would like to eventually rename the dlls but at this point I have not found a viable solution where I would not have to deploy something to the client as well. 我想最终重命名dll,但是到现在为止,我还没有找到一个可行的解决方案,在该解决方案中,我也不必向客户端部署某些东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM