Try the following:
public sealed class CurrentAssemblyDeserializationBinder : SerializationBinder { public override Type BindToType(string assemblyName, string typeName) { return Type.GetType(String.Format("{0}, {1}", typeName, Assembly.GetExecutingAssembly().FullName)); } } formatter.Binder = new CurrentAssemblyDeserializationBinder(); formatter.Deserialize(inStream);
Added:
Yes it works. Just make sure that there are any types of System.Generic or other Libs in the binary data, then you must pass them unchanged. "ResizableControls" is the name of the old lib assembly, "EntityLib" is the new assembly name. In addition, the version number must also be replaced upon request.
public sealed class CurrentAssemblyDeserializationBinder : SerializationBinder { public override Type BindToType(string assemblyName, string typeName) { string name; if (assemblyName.Contains("ResizableControl")) { name = Assembly.GetAssembly(typeof(EntityLib.Pattern)).ToString(); } else { name = assemblyName; } return Type.GetType(String.Format("{0}, {1}", typeName.Replace("ResizableControl", "EntityLib"), name)); } }
Thank you, this is exactly what I need.
Jacob Seleznev
source share